[stringbuf.cons] # 31 Input/output library [[input.output]](./#input.output) ## 31.8 String-based streams [[string.streams]](string.streams#stringbuf.cons) ### 31.8.2 Class template basic_stringbuf [[stringbuf]](stringbuf#cons) #### 31.8.2.2 Constructors [stringbuf.cons] [🔗](#lib:basic_stringbuf,constructor) `explicit basic_stringbuf(ios_base::openmode which); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8150) *Effects*: Initializes the base class withbasic_streambuf() ([[streambuf.cons]](streambuf.cons "31.6.3.2 Constructors")), and*mode* with which[.](#1.sentence-1) It isimplementation-defined whether the sequence pointers (eback(), gptr(), egptr(),pbase(), pptr(), epptr()) are initialized to null pointers[.](#1.sentence-2) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8163) *Postconditions*: str().empty() is true[.](#2.sentence-1) [🔗](#lib:basic_stringbuf,constructor_) `explicit basic_stringbuf( const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8176) *Effects*: Initializes the base class withbasic_streambuf() ([[streambuf.cons]](streambuf.cons "31.6.3.2 Constructors")),*mode* with which, and*buf* with s, then calls *init-buf-ptrs*()[.](#3.sentence-1) [🔗](#lib:basic_stringbuf,constructor__) `basic_stringbuf(ios_base::openmode which, const Allocator& a); ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8191) *Effects*: Initializes the base class withbasic_streambuf() ([[streambuf.cons]](streambuf.cons "31.6.3.2 Constructors")),*mode* with which, and*buf* with a, then calls *init-buf-ptrs*()[.](#4.sentence-1) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8199) *Postconditions*: str().empty() is true[.](#5.sentence-1) [🔗](#lib:basic_stringbuf,constructor___) `explicit basic_stringbuf( basic_string&& s, ios_base::openmode which = ios_base::in | ios_base::out); ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8212) *Effects*: Initializes the base class with basic_streambuf() ([[streambuf.cons]](streambuf.cons "31.6.3.2 Constructors")),*mode* with which, and*buf* with std​::​move(s), then calls *init-buf-ptrs*()[.](#6.sentence-1) [🔗](#lib:basic_stringbuf,constructor____) `template basic_stringbuf( const basic_string& s, ios_base::openmode which, const Allocator& a); ` [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8229) *Effects*: Initializes the base class with basic_streambuf() ([[streambuf.cons]](streambuf.cons "31.6.3.2 Constructors")),*mode* with which, and*buf* with {s,a}, then calls *init-buf-ptrs*()[.](#7.sentence-1) [🔗](#lib:basic_stringbuf,constructor_____) `template explicit basic_stringbuf( const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8246) *Constraints*: is_same_v is false[.](#8.sentence-1) [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8250) *Effects*: Initializes the base class with basic_streambuf() ([[streambuf.cons]](streambuf.cons "31.6.3.2 Constructors")),*mode* with which, and*buf* with s, then calls *init-buf-ptrs*()[.](#9.sentence-1) [🔗](#lib:basic_stringbuf,constructor______) `template explicit basic_stringbuf(const T& t, ios_base::openmode which = ios_base::in | ios_base::out); template basic_stringbuf(const T& t, const Allocator& a); template basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8269) Let which be ios_base​::​in | ios_base​::​out for the overload with no parameter which, anda be Allocator() for the overload with no parameter a[.](#10.sentence-1) [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8274) *Constraints*: is_convertible_v> is true[.](#11.sentence-1) [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8279) *Effects*: Creates a variable sv as if bybasic_string_view sv = t, then value-initializes the base class, initializes *mode* with which, and direct-non-list-initializes *buf* with sv, a, then calls *init-buf-ptrs*()[.](#12.sentence-1) [🔗](#lib:basic_stringbuf,constructor_______) `basic_stringbuf(basic_stringbuf&& rhs); basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a); ` [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8296) *Effects*: Copy constructs the base class from rhs and initializes *mode* with rhs.mode[.](#13.sentence-1) In the first form buf is initialized from std​::​move(rhs).str()[.](#13.sentence-2) In the second form *buf* is initialized from {std​::​move(rhs).str(), a}[.](#13.sentence-3) It isimplementation-defined whether the sequence pointers in *this (eback(), gptr(), egptr(),pbase(), pptr(), epptr()) obtain the values which rhs had[.](#13.sentence-4) [14](#14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8311) *Postconditions*: Let rhs_p refer to the state ofrhs just prior to this construction and let rhs_a refer to the state of rhs just after this construction[.](#14.sentence-1) - [(14.1)](#14.1) str() == rhs_p.str() - [(14.2)](#14.2) gptr() - eback() == rhs_p.gptr() - rhs_p.eback() - [(14.3)](#14.3) egptr() - eback() == rhs_p.egptr() - rhs_p.eback() - [(14.4)](#14.4) pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase() - [(14.5)](#14.5) epptr() - pbase() == rhs_p.epptr() - rhs_p.pbase() - [(14.6)](#14.6) if (eback()) eback() != rhs_a.eback() - [(14.7)](#14.7) if (gptr()) gptr() != rhs_a.gptr() - [(14.8)](#14.8) if (egptr()) egptr() != rhs_a.egptr() - [(14.9)](#14.9) if (pbase()) pbase() != rhs_a.pbase() - [(14.10)](#14.10) if (pptr()) pptr() != rhs_a.pptr() - [(14.11)](#14.11) if (epptr()) epptr() != rhs_a.epptr() - [(14.12)](#14.12) getloc() == rhs_p.getloc() - [(14.13)](#14.13) rhs is empty but usable, as if std​::​move(rhs).str() was called.