tags:

views:

109

answers:

1

I can do

std::ostringstream oss;
oss << 1;
oss.str();

so why can't I do:

((std::ostringstream()) << 1).str() ?

Thanks!

+10  A: 

The << operator returns the base type ostream, while the str member function exists only on the derived type ostringstream.

interjay
(oss<<1).str() fails the same way. ostream doesnt support str()
pm100
could you cast it back up to an ostringstream?
Inverse
Yes, casting it back would work.
interjay