> > string s;
ostringstream strm(s); // This stream should store results in s
Where did you get the idea that the comment above is correct?
"Beginning C++" by Ivor Horton, 1998 ed., page 802, states (apparently
incorrectly):
You can use an ostringstream object to format data into a string. For
instance, you could create a string object and an output string stream with
the statements:
string outBuffer;
ostringstream outStr(outBuffe r);
You can now use the insertion operators to write to outBuffer via outStr:
double number = 2.5;
outStr << "number = " << (number / 2);
As a result of the write to the string stream, outBuffer will contain
"Number = 1.25"... The string parameter to the string stream constructor is
a reference, so write operations for ostringstream objects act directly on
the string object.