The C++ style will use the C++ string type and a new type: stringstream.
The stringstream type is similar to ostream and istream in that it allows both << and >> operators.
In fact stringstream inherits all the methods and operators from istream and ostream.
The << operator allows the different types to be "inserted" into the stringstream just as for ostream.
Just as for ostream, values inserted into a stringstream are converted to a string!
However, the stringstream object has a string buffer where it stores this string rather than sending the string to standard output.
There are three stringstream methods that manage the string buffer of a stringstream:
- void clear() - sets the buffer to the empty string.
- string str() - returns a copy of the string in the buffer.
- void str(string s) - sets the buffer's contents to be s.