C + + introduces the three classes of Ostringstream, Istringstream, StringStream, which are included in the sstream.h header file. In three classes
1) The Istringstream class is used to perform input operations of C + + style streaming;
2) The Ostringstream class is used to perform C-style streaming output operations;
3) The Strstream class can support both styles of streaming input and output operations.
First, StringStream
One of the important functions of stringstream is to make the conversion of data, which is more safe and convenient than other implementations.
1) The value turns into a string:
In the code we first declare an integer n using the scientific notation, then declare a Stringsteam instance STRM, then the integer n "flows" into the STRM, and then let the STRM data "out" into S, the successful completion of the conversion, the results of the operation are as follows:
2) string into numeric value:
In the code we first declare a string class S, let it flow into the STRM and then stream to N, and then successfully turn S into double:
However, if we declare the type of n as int, the conversion is still successful, except that the value of n will be 1 because n is not int, so the decimal conversion will end when "Inflow" N from STRM.
To IS continued.
C + + StringStream