stringstream::stringstream
[constructor] explicit stringstream ( openmode mode = in | out ); explicit stringstream ( const string & str, openmode mode = in | out ); | stringstream |
cplusplus.com |
Construct an object and optionally initialize string content.
Constructs an object of class stringstream including the initialization of the
associated stringbuf object and the call to its base class' constructor with the
stringbuf object as constructor parameter.
Additionally, in case the second constructor syntax is used, the stream's buffer is
initialized with the content of the STL string object str as if a call to
member str.
Parameters.
bit effect app (append) Seek to the end of the stream before each output operation. ate (at end) Seek to the end of the stream when opening. binary Consider stream as binary rather than text. in Allow input operations on a stream. out Allow output operations on a stream. trunc (truncate) Truncate file to zero when opening.
Return Value.
none
Example.
// using stringstream constructors.
#include <iostream>
#include <sstream>
using namespace std;
int main () {
int val;
string mystr;
stringstream ss (stringstream::in | stringstream::out);
ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++)
{
ss >> val;
cout << val*2 << endl;
}
return 0;
}
This example uses the constructor to declare a stringstream for both input and output
operations. A string is inserted into the stringstream and then it is extracted
as integer values.
Basic template member declaration ( basic_stringstream<charT,traits,Allocator> ):
explicit basic_stringstream ( openmode mode = in | out ); explicit basic_stringstream ( const basic_string<charT,traits,Allocator> * str, openmode mode = in | out ); |
See also.
str
stringstream class