public member function
<sstream>

std::istringstream::istringstream

default (1)
explicit istringstream (ios_base::openmode which = ios_base::in);
initialization (2)
explicit istringstream (const string& str,
                        ios_base::openmode which = ios_base::in);
default (1)
explicit istringstream (ios_base::openmode which = ios_base::in);
initialization (2)
explicit istringstream (const string& str,
                        ios_base::openmode which = ios_base::in);
copy (3)
istringstream (const istringstream&) = delete;
move (4)
istringstream (istringstream&& x);
Construct object
Constructs a istringstream object:

(1) empty constructor (default constructor)
Constructs an istringstream object with an empty sequence as content.
Internally, its istream base constructor is passed a pointer to a stringbuf object constructed with an argument based on which.
(2) initialization constructor
Constructs an istringstream object with a copy of str as content.
Internally, its istream base constructor is passed a pointer to a stringbuf object constructed with arguments based on str and which.
(3) copy constructor (deleted)
Deleted (no copy constructor).
(4) move constructor
Acquires the contents of x.
First, the function move-constructs both its base istream class from x and a stringbuf object from x's internal streambuf object, and then associates them by calling member set_rdbuf.
x is left in an unspecified but valid state.
It is unspecified whether the sequence controlled by the internal stringbuf object is the one in x before the call, or a copy of it. In any case, both objects have internal string buffers that use independent sequences after the call.
The internal stringbuf object has at least the same duration as the istringstream object.

Parameters

str
A string object, whose content is copied.
x
A istringstream object, whose value is moved.
which
Open mode: Access given by the internal stringbuf object to its internal sequence of characters. It is an object of member type openmode for which any combination of the following member values is significant:
member constantstands foraccess
ios_base::in*inputThe sequence supports input operations.
ios_base::outoutputThe sequence supports output operations.
Other values of type ios_base::openmode may also be specified, although whether they have an effect on istringstream objects depends on the library implementation.
member constantstands foraccess
ios_base::in*inputThe sequence supports input operations.
ios_base::outoutputThe sequence supports output operations.
ios_base::ateat endThe writing position is at the end after construction, and after every time the content is reset with member str.
Other values of type ios_base::openmode (such as ios_base::app) may also be specified, although whether they have an effect on istringstream objects depends on the library implementation.
* ios_base::in is always set for istringstream objects (even if explicitly not set in argument which).
Note that even though istringstream is an input stream, its internal stringbuf object may be set to also support output operations. This influences certain operations, such as putback, that in istringstream may alter the contents of the sequence.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// istringstream constructors.
#include <iostream>     // std::cout
#include <sstream>      // std::istringstream
#include <string>       // std::string

int main () {

  std::string stringvalues = "125 320 512 750 333";
  std::istringstream iss (stringvalues);

  for (int n=0; n<5; n++)
  {
    int val;
    iss >> val;
    std::cout << val*2 << '\n';
  }

  return 0;
}


Output:
250
640
1024
1500
666

Data races

The move constructor (4) modifies x.

Exception safety

Strong guarantee: if an exception is thrown, there are no side effects.

See also