First case: the output is normal.
# Include <isotream>
# Include <sstream>
# Include <string>
Using namespce STD;
String inttostring (int)
{
Ostringstream ostr;
Ostr String STR = ostr. STR ();
Cout <STR;
Return STR;
}
Case 2: Garbled output
# Include <isotream>
# Include <sstream>
# Include <string>
Using namespce STD;
String inttostring (int)
{
Ostrstream ostr;
Ostr String STR = ostr. STR ();
Cout <STR;
Return STR;
}
========================================================== ========================================
Ostrstream: Derived from ostream (output stream class) and strstreambase (string stream base class)
Istrstream: Derived from istream (input stream class) and strstreambase (string stream base class)
Strstream: Derived from iostream (input/output stream class) and strstreambase (string stream base class)
The istrstream class is used to perform input operations for a C-style stream, that is, an array of strings as the input device.
The ostrstream class is used to perform input operations for a C-style stream, that is, an array of strings as the input device.
The strstream class is used to perform C-style Stream Input and Output operations.
Ostringstream
Istringstream
In C ++, there are two types of string streams. One is defined in sstream and the other is defined in strstream. Their implementations are basically the same.
Strstream includes:
Class strstrambuf;
Class istrstream
Class ostrstream;
Class strstream;
They are written based on the C string char.
Sstream includes:
Class istringstream
Class ostringstream
Class stringbuf
Class stringstream
They are written based on STD: string.
Therefore, ostringstream: STR () returns a string of the STD: string type, and ostrstream: STR () returns a string of the char * type.
Pay attention to the differences between the two. Generally, STD: string is recommended.