std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream (3) - Linux Manuals
std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream: std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
Command to display std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
manual in Linux: $ man 3 std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
NAME
std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream - std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
Synopsis
basic_stringstream() : basic_stringstream(ios_base::in|ios_base::out) { } (1) (since C++11)
explicit basic_stringstream( ios_base::openmode mode = ios_base::in|ios_base::out ); (until C++11)
explicit basic_stringstream( ios_base::openmode mode ); (since C++11)
explicit basic_stringstream( const std::basic_string<CharT,Traits,Allocator>& str, (2) (3)
ios_base::openmode mode = ios_base::in|ios_base::out );
basic_stringstream( basic_stringstream&& other ); (4) (since C++11)
Constructs new string stream.
1) Default constructor. Constructs new underlying string device with the default open mode
2) Constructs new underlying string device. The underlying basic_stringbuf object is constructed as basic_stringbuf<Char,Traits,Allocator>(mode).
3) 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).
4) 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
specifies stream open mode. It is bitmask type, the following constants are defined:
Constant Explanation
app seek to the end of stream before each write
mode - binary open in binary_mode
in open for reading
out open for writing
trunc discard the contents of the stream when opening
ate seek to the end of stream immediately after open
other - another string stream to use as source
Notes
Construction of one-off basic_stringstream objects in a tight loop, such as when used for string conversion, may be significantly more costly than calling str to reuse the same object.
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
P0935R0 C++11 default constructor was explicit made implicit
Example
// Run this code
#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:
buf1 = 7 n = 7
n = -10
test1
See also
gets or sets the contents of underlying string device object
str (public member function)
constructs a basic_stringbuf object
constructor (public member function of std::basic_stringbuf<CharT,Traits,Allocator>)
Pages related to std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
- std::basic_stringstream<CharT,Traits,Allocator>::str (3) - std::basic_stringstream<CharT,Traits,Allocator>::str
- std::basic_stringstream (3) - std::basic_stringstream
- std::basic_stringstream::operator= (3) - std::basic_stringstream::operator=
- std::basic_stringstream::rdbuf (3) - std::basic_stringstream::rdbuf
- std::basic_stringstream::swap (3) - std::basic_stringstream::swap
- std::basic_string (3) - std::basic_string
- std::basic_string<CharT,Traits,Allocator>::append (3) - std::basic_string<CharT,Traits,Allocator>::append
- std::basic_string<CharT,Traits,Allocator>::assign (3) - std::basic_string<CharT,Traits,Allocator>::assign
- std::basic_string<CharT,Traits,Allocator>::at (3) - std::basic_string<CharT,Traits,Allocator>::at
- std::basic_string<CharT,Traits,Allocator>::back (3) - std::basic_string<CharT,Traits,Allocator>::back
- std::basic_string<CharT,Traits,Allocator>::basic_string (3) - std::basic_string<CharT,Traits,Allocator>::basic_string
- std::basic_string<CharT,Traits,Allocator>::begin, (3) - std::basic_string<CharT,Traits,Allocator>::begin,
- std::basic_string<CharT,Traits,Allocator>::begin,std::basic_string<CharT,Traits,Allocator>::cbegin (3) - std::basic_string<CharT,Traits,Allocator>::begin,std::basic_string<CharT,Traits,Allocator>::cbegin
- std::basic_string<CharT,Traits,Allocator>::c_str (3) - std::basic_string<CharT,Traits,Allocator>::c_str
- std::basic_string<CharT,Traits,Allocator>::capacity (3) - std::basic_string<CharT,Traits,Allocator>::capacity
- std::basic_string<CharT,Traits,Allocator>::clear (3) - std::basic_string<CharT,Traits,Allocator>::clear
- std::basic_string<CharT,Traits,Allocator>::compare (3) - std::basic_string<CharT,Traits,Allocator>::compare
- std::basic_string<CharT,Traits,Allocator>::copy (3) - std::basic_string<CharT,Traits,Allocator>::copy
- std::basic_string<CharT,Traits,Allocator>::data (3) - std::basic_string<CharT,Traits,Allocator>::data
- std::basic_string<CharT,Traits,Allocator>::empty (3) - std::basic_string<CharT,Traits,Allocator>::empty
- std::basic_string<CharT,Traits,Allocator>::end, (3) - std::basic_string<CharT,Traits,Allocator>::end,