Hi,
The reasoning behind the interface is that stringstream is not
implemented in terms of a string, but to format things passed to the
stream as a string.
The representation inside a stringstream (inside the string buffer
actually) is optimized for speed and memory usage (which is why it's
better to use stringstream instead of string for more complex string
operations).
The str() function doesn't return the internal representation of the
string, as in the internal representation there is no string. Instead,
it builds a string upon request and returns that. The string is a
copy, not the internal representation.
This is (should be) lazy evaluation, as the string is constructed only
if needed (and returned as a temporary).
The same holds true for the str(std::string const&) function: it
adjusts the internal buffer of the stringstream to copy the contents
of the string. In broad terms (and broad terms only) it copies the
string internally.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
stringstream misunderstanding