[stringbuf.general] # 31 Input/output library [[input.output]](./#input.output) ## 31.8 String-based streams [[string.streams]](string.streams#stringbuf.general) ### 31.8.2 Class template basic_stringbuf [[stringbuf]](stringbuf#general) #### 31.8.2.1 General [stringbuf.general] [🔗](#lib:basic_stringbuf) namespace std {template, class Allocator = allocator>class basic_stringbuf : public basic_streambuf {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; // [[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"), constructors basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {}explicit basic_stringbuf(ios_base::openmode which); explicit basic_stringbuf(const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); explicit basic_stringbuf(const Allocator& a): basic_stringbuf(ios_base::in | ios_base::out, a) {} basic_stringbuf(ios_base::openmode which, const Allocator& a); explicit basic_stringbuf( basic_string&& s, ios_base::openmode which = ios_base::in | ios_base::out); template basic_stringbuf(const basic_string& s, const Allocator& a): basic_stringbuf(s, ios_base::in | ios_base::out, a) {}template basic_stringbuf(const basic_string& s, ios_base::openmode which, const Allocator& a); templateexplicit basic_stringbuf(const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); templateexplicit 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); basic_stringbuf(const basic_stringbuf&) = delete; basic_stringbuf(basic_stringbuf&& rhs); basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a); // [[stringbuf.assign]](stringbuf.assign "31.8.2.3 Assignment and swap"), assignment and swap basic_stringbuf& operator=(const basic_stringbuf&) = delete; basic_stringbuf& operator=(basic_stringbuf&& rhs); void swap(basic_stringbuf& rhs) noexcept(*see below*); // [[stringbuf.members]](stringbuf.members "31.8.2.4 Member functions"), getters and setters allocator_type get_allocator() const noexcept; basic_string str() const &; template basic_string str(const SAlloc& sa) const; basic_string str() &&; basic_string_view view() const noexcept; void str(const basic_string& s); templatevoid str(const basic_string& s); void str(basic_string&& s); templatevoid str(const T& t); protected:// [[stringbuf.virtuals]](stringbuf.virtuals "31.8.2.5 Overridden virtual functions"), overridden virtual functions int_type underflow() override; int_type pbackfail(int_type c = traits::eof()) override; int_type overflow (int_type c = traits::eof()) override; basic_streambuf* setbuf(charT*, streamsize) override; pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out) override; pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out) override; private: ios_base::openmode *mode*; // *exposition only* basic_string *buf*; // *exposition only*void *init-buf-ptrs*(); // *exposition only*};} [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8113) The classbasic_stringbuf is derived frombasic_streambuf to associate possibly the input sequence and possibly the output sequence with a sequence of arbitrary[*characters*](#def:characters)[.](#1.sentence-1) The sequence can be initialized from, or made available as, an object of classbasic_string[.](#1.sentence-2) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8124) For the sake of exposition, the maintained data and internal pointer initialization is presented here as: - [(2.1)](#2.1) ios_base​::​openmode *mode*, has in set if the input sequence can be read, and out set if the output sequence can be written[.](#2.1.sentence-1) - [(2.2)](#2.2) basic_string *buf* contains the underlying character sequence[.](#2.2.sentence-1) - [(2.3)](#2.3) *init-buf-ptrs*() sets the base class' get area ([[streambuf.get.area]](streambuf.get.area "31.6.3.4.2 Get area access")) and put area ([[streambuf.put.area]](streambuf.put.area "31.6.3.4.3 Put area access")) pointers after initializing, moving from, or assigning to *buf* accordingly[.](#2.3.sentence-1)