iostream hierarchy
istringstream:: istringstream [constructor]
  cplusplus.com  
explicit istringstream ( openmode mode = in );
explicit istringstream ( const string & str, openmode mode = in );

Construct an object and optionally initialize string content.
  Constructs an object of class istringstream 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.

mode
Flags describing 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 the following flags (member constants):
biteffect
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.
binaryConsider stream as binary rather than text.
inAllow input operations on a stream.
outAllow output operations on a stream.
trunc(truncate) Truncate file to zero when opening.
str
String object to be copied to internal buffer. This is an STL string object.

Return Value.
  none

Example.

// using istringstream constructors.
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main () {

  int n,val;
  string strvalues;

  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 a stringstream using the constructor and uses standard extractor operator to extract the values contained in the stringstream as integer values. An aritmetic operation (duplication) is performed on the values before being output.

Basic template member declaration ( basic_istringstream<charT,traits,Allocator> ):
explicit basic_istringstream ( openmode mode = in );
explicit basic_istringstream ( const basic_string<charT,traits,Allocator> * str, openmode mode = in );

See also.
  str
  istringstream class


© The C++ Resources Network, 2001