| (1) | |||
| (2) | |||
| (3) | (since C++11) |
Constructs new string stream.
1) Constructs new underlying string device. The underlying basic_stringbuf
object is constructed as basic_stringbuf<Char,Traits,Allocator>(mode | ios_base::in)
.
2) Uses a copy of str
as initial contents of the underlying string device. The underlying basic_stringbuf
object is constructed as basic_stringbuf<Char,Traits,Allocator>(str, mode | ios_base::in)
.
3) Move constructor. Constructs the string stream with the state of other
using move semantics.
Parameters
str | - | string to use as initial contents of the string stream | ||||||||||||||
mode | - | specifies stream open mode. It is bitmask type, the following constants are defined:
| ||||||||||||||
other | - | another string stream to use as source |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> #include <sstream> int main() { // default constructor (input/output stream) std::stringstream buf1; buf1 << 7; int n = 0; buf1 >> n; std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n' ; // input stream std::istringstream inbuf( "-10" ); inbuf >> n; std::cout << "n = " << n << '\n' ; // output stream in append mode (C++11) std::ostringstream buf2( "test" , std::ios_base::ate); buf2 << '1' ; std::cout << buf2.str() << '\n' ; } |
Output:
1 2 3 | buf1 = 7 n = 7 n = -10 test1 |
See also
gets or sets the contents of underlying string device object (public member function) | |
constructs a basic_stringbuf object (public member function of std::basic_stringbuf ) |
Please login to continue.