public member function
<sstream>
std::stringstream::stringstream
| default (1) | explicit stringstream (ios_base::openmode which = ios_base::in | ios_base::out); |
|---|---|
| initialization (2) | explicit stringstream (const string& str, ios_base::openmode which = ios_base::in | ios_base::out); |
| default (1) | explicit stringstream (ios_base::openmode which = ios_base::in | ios_base::out); |
|---|---|
| initialization (2) | explicit stringstream (const string& str, ios_base::openmode which = ios_base::in | ios_base::out); |
| copy (3) | stringstream (const stringstream&) = delete; |
| move (4) | stringstream (stringstream&& x); |
Construct object
- (1) empty constructor (default constructor)
- Constructs a stringstream object with an empty sequence as content.
Internally, its iostream base constructor is passed a pointer to a stringbuf object constructed with which as argument. - (2) initialization constructor
- Constructs a stringstream object with a copy of str as content.
Internally, its iostream base constructor is passed a pointer to a stringbuf object constructed with str and which as arguments. - (3) copy constructor (deleted)
- Deleted (no copy constructor).
- (4) move constructor
- Acquires the contents of x.
First, the function move-constructs both its base iostream 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.
Parameters
- str
- A string object, whose content is copied.
- x
- A stringstream 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 constant stands for access ios_base::in input The sequence supports input operations. ios_base::out output The sequence supports output operations. Other values of type ios_base::openmode may also be specified, although whether they have an effect on stringstream objects depends on the library implementation.
member constant stands for access ios_base::in input The sequence supports input operations. ios_base::out output The sequence supports output operations. ios_base::ate at end The 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 stringstream objects depends on the library implementation.
Example
|
|
Output:
Data races
The move constructor (4) modifies x.Exception safety
Strong guarantee: if an exception is thrown, there are no side effects.See also
- stringstream::str
- Get/set content (public member function)