std::basic_stringbuf<CharT,Traits,Allocator>::basic_stringbuf
std::ios_base::in | std::ios_base::out );
: basic_stringbuf( std::ios_base::in | std::ios_base::out ) {}
basic_stringbuf( const std::basic_string <CharT, Traits, Allocator>& s,
std::ios_base::openmode which =
std::ios_base::openmode which =
: basic_stringbuf( std::ios_base::in | std::ios_base::out, a ) {}
explicit basic_stringbuf( const std::basic_string <CharT, Traits, SAlloc>& s,
std::ios_base::openmode which =
basic_stringbuf( const std::basic_string <CharT, Traits, SAlloc>& s,
basic_stringbuf( const std::basic_string <CharT, Traits, SAlloc>& s,
const Allocator& a )
explicit basic_stringbuf( const StringViewLike& t,
std::ios_base::openmode which =
basic_stringbuf( const StringViewLike& t,
basic_stringbuf( const StringViewLike& t, const Allocator& a );
The std::basic_streambuf base and the exposition-only data members buf
and mode
are initialized as follows.
After initializing these subobjects, overloads (3-12) initialize the input and output sequences as if by calling init_buf_ptrs()
.
Overload | std::basic_streambuf base | buf
|
mode
|
---|---|---|---|
(1) | default-initialized | implementation-defined (see below) |
which |
(2) | std::ios_base::in | std::ios_base::out | ||
(3) | s | which | |
(4) | std::move(s) | ||
(5) | a | ||
(6) | std::ios_base::in | std::ios_base::out | ||
(7) | s | which | |
(8) | {s, a} | ||
(9) | std::ios_base::in | std::ios_base::out | ||
(10) | {sv, Allocator()} | which | |
(11) | {sv, a} | ||
(12) | std::ios_base::in | std::ios_base::out | ||
(13) | rhs (copy constructed) |
std::move(rhs).str() | rhs.mode |
(14) | {std::move(rhs).str(), a} |
std::basic_string_view <CharT, Traits>> is true.
- Let rhs_p refer to the state of rhs just prior to this construction, the following expressions will evaluate to true:
- str() == rhs_p.str()
- getloc() == rhs_p.getloc()
- gptr() - eback() == rhs_p.gptr() - rhs_p.eback()
- egptr() - eback() == rhs_p.egptr() - rhs_p.eback()
- pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()
- epptr() - pbase() == rhs_p.epptr() - rhs_p.pbase()
- Let rhs_a refer to the state of rhs just after this construction, the following expressions will evaluate to true:
- !eback() || eback() != rhs_a.eback()
- !gptr() || gptr() != rhs_a.gptr()
- !egptr() || egptr() != rhs_a.egptr()
- !pbase() || pbase() != rhs_a.pbase()
- !pptr() || pptr() != rhs_a.pptr()
- !epptr() || epptr() != rhs_a.epptr()
[edit] Parameters
basic_stringbuf
[edit] Notes
Typically called by the constructor of std::basic_stringstream .
The level of support for the open modes other than std::ios_base::in and std::ios_base::out varies among implementations. C++11 explicitly specifies the support for std::ios_base::ate in str() and in this constructor, but std::ios_base::app , std::ios_base::trunc , and std::ios_base::binary have different effects on different implementations.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_sstream_from_string_view |
202306L |
(C++26) | Interfacing string streams with std::string_view |
[edit] Example
Demonstrates calling the constructor of std::basic_stringbuf
directly:
#include <iostream> #include <sstream> int main() { // default constructor (mode = in | out) std::stringbuf buf1; buf1.sputc('1'); std::cout << &buf1 << '\n'; // string constructor in at-end mode (C++11) std::stringbuf buf2("test", std::ios_base::in | std::ios_base::out | std::ios_base::ate ); buf2.sputc('1'); std::cout << &buf2 << '\n'; // append mode test (results differ among compilers) std::stringbuf buf3("test", std::ios_base::in | std::ios_base::out | std::ios_base::app ); buf3.sputc('1'); buf3.pubseekpos(1); buf3.sputc('2'); std::cout << &buf3 << '\n'; }
Output:
1 test1 est12 (Sun Studio) 2st1 (GCC)
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 432 | C++98 | 1. overload (1) allocated no array object 2. overload (3) did not specify how the input and output sequences are initialized |
1. removed the limitation 2. specified |
LWG 562 | C++98 | overload (3) set epptr() to point one past the last underlying character if bool(which & std::ios_base::out ) == true |
epptr() can be set beyond that position |
P0935R0 | C++11 | the default constructor was explicit | made implicit |
[edit] See also
(public member function of
std::basic_stringstream<CharT,Traits,Allocator>
) [edit]