Header file for input and output <iostream>
Header file of the string stream <sstream>
File stream header file <fstream>
Usage of stringstream
1. Use input and output for Data Conversion
StringstreamSs_stream;
Ss_stream <I;// Input int to the stream
Ss_stream>Str;// Output the value in ss_stream to Str
// Note: if multiple data conversions are performed, you must call clear () to set the conversion mode.
Ss_stream <"456";
Ss_stream> I;// First convert the string to int
Ss_stream.Clear();
Ss_stream <True;
Ss_stream> I;// Convert the bool type to int type. If clear is not performed before, the I will fail.
// Result of running clear
I = 456.
I = 1
// No result for running clear
I = 456.
I = 8800090900.
2. Support for input and output of char *
CharSz_buf [20];
Ss_stream <8888;
Ss_stream> sz_buf; // directly output the number to the sz_buf character array.
3. to store the list of variable data
Stringstream Ss_stream;
Ss_stream < "String 1" < Endl ;
Ss_stream < "String 2" < Endl ;
Ss_stream < "String 3" < Endl ;
Ss_stream <"String 4" < Endl ;
Ss_stream < "String 5" < Endl ;
Char Buffer [100];
While (Ss_stream.getline (buffer, Sizeof (Buffer ))
{
Printf ( "MSG = % s \ n" , Buffer );
}
Ss_stream ("" ); // Release resources in the string stream
// Or use string to receive
Stringstream Ss_stream;
String Stemp;
While (Getline (ss_stream, stemp ))
{
Task_download (stemp. C_str (), Relate. C_str ());
}