explicit istringstream ( openmode which = ios_base::in );
explicit istringstream ( const string & str, openmode which = ios_base::in );
Construct an object and optionally initialize its content
Constructs an object of class istringstream including the initialization of the associated stringbuf object and the call to its base class's constructor with the initialized stringbuf object as constructor parameter.
Additionally, in case that the second constructor version is used, the stream's buffer is initialized with the content of the string object str as if a call to member str.
Parameters
- which
- Bitmask with the requested i/o mode for the string buffer. This is an object of type ios_base::openmode. It generally consists of a combination of one or more the following flags (which are member constants):
flag value | opening mode |
app | (append) Set the stream's position indicator to the end of the stream before each output operation. |
ate | (at end) Set the stream's position indicator to the end of the stream on opening. |
binary | (binary) Consider stream as binary rather than text. |
in | (input) Allow input operations on the stream. |
out | (output) Allow output operations on the stream. |
trunc | (truncate) Any current content is discarded, assuming a length of zero on opening. |
- str
- string object to be copied as the initial value for the internal buffer string.
Return Value
none
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// using istringstream constructors.
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main () {
int n,val;
string stringvalues;
stringvalues = "125 320 512 750 333";
istringstream iss (stringvalues,istringstream::in);
for (n=0; n<5; n++)
{
iss >> val;
cout << val*2 << endl;
}
return 0;
}
|
This example associates a string with an istringstream using the constructor and then uses standard extractor operator to extract the values contained in the stringstream as integer values.
Basic template member declaration
( basic_istringstream<charT,traits,Allocator> )
1 2 3
|
explicit basic_istringstream ( openmode which = ios_base::in );
explicit basic_istringstream ( const basic_string<charT,traits,Allocator> * str,
openmode which = ios_base::in );
|
See also
|