previous | start | next

Writing a toString() Method: 3

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:



previous | start | next