[string.streams]

# 31 Input/output library [[input.output]](./#input.output)

## 31.8 String-based streams [string.streams]

### [31.8.1](#sstream.syn) Header <sstream> synopsis [[sstream.syn]](sstream.syn)

[ð](#header:%3csstream%3e)

namespace std {// [[stringbuf]](#stringbuf "31.8.2 Class template basic_­stringbuf"), class template basic_stringbuftemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_stringbuf; template<class charT, class traits, class Allocator>void swap(basic_stringbuf<charT, traits, Allocator>& x,
 basic_stringbuf<charT, traits, Allocator>& y) noexcept(noexcept(x.swap(y))); using stringbuf = basic_stringbuf<char>; using wstringbuf = basic_stringbuf<wchar_t>; // [[istringstream]](#istringstream "31.8.3 Class template basic_­istringstream"), class template basic_istringstreamtemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_istringstream; template<class charT, class traits, class Allocator>void swap(basic_istringstream<charT, traits, Allocator>& x,
 basic_istringstream<charT, traits, Allocator>& y); using istringstream = basic_istringstream<char>; using wistringstream = basic_istringstream<wchar_t>; // [[ostringstream]](#ostringstream "31.8.4 Class template basic_­ostringstream"), class template basic_ostringstreamtemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_ostringstream; template<class charT, class traits, class Allocator>void swap(basic_ostringstream<charT, traits, Allocator>& x,
 basic_ostringstream<charT, traits, Allocator>& y); using ostringstream = basic_ostringstream<char>; using wostringstream = basic_ostringstream<wchar_t>; // [[stringstream]](#stringstream "31.8.5 Class template basic_­stringstream"), class template basic_stringstreamtemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_stringstream; template<class charT, class traits, class Allocator>void swap(basic_stringstream<charT, traits, Allocator>& x,
 basic_stringstream<charT, traits, Allocator>& y); using stringstream = basic_stringstream<char>; using wstringstream = basic_stringstream<wchar_t>;}

[1](#sstream.syn-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8012)

The header [<sstream>](#header:%3csstream%3e "31.8.1 Header <sstream> synopsis [sstream.syn]") defines four class templates
and eight types that associate stream buffers with objects of classbasic_string,as described in [[string.classes]](string.classes "27.4 String classes")[.](#sstream.syn-1.sentence-1)

### [31.8.2](#stringbuf) Class template basic_stringbuf [[stringbuf]](stringbuf)

#### [31.8.2.1](#stringbuf.general) General [[stringbuf.general]](stringbuf.general)

[ð](#lib:basic_stringbuf)

namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_stringbuf : public basic_streambuf<charT, traits> {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<charT, traits, Allocator>& 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<charT, traits, Allocator>&& s,
 ios_base::openmode which = ios_base::in | ios_base::out); template<class SAlloc> basic_stringbuf(const basic_string<charT, traits, SAlloc>& s, const Allocator& a): basic_stringbuf(s, ios_base::in | ios_base::out, a) {}template<class SAlloc> basic_stringbuf(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which, const Allocator& a); template<class SAlloc>explicit basic_stringbuf(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which = ios_base::in | ios_base::out); template<class T>explicit basic_stringbuf(const T& t,
 ios_base::openmode which = ios_base::in | ios_base::out); template<class T> basic_stringbuf(const T& t, const Allocator& a); template<class T> 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<charT, traits, Allocator> str() const &; template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
 basic_string<charT, traits, Allocator> str() &&;
 basic_string_view<charT, traits> view() const noexcept; void str(const basic_string<charT, traits, Allocator>& s); template<class SAlloc>void str(const basic_string<charT, traits, SAlloc>& s); void str(basic_string<charT, traits, Allocator>&& s); template<class T>void 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<charT, traits>* 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<charT, traits, Allocator> *buf*; // *exposition only*void *init-buf-ptrs*(); // *exposition only*};}

[1](#stringbuf.general-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)[.](#stringbuf.general-1.sentence-1)

The sequence can be initialized from, or made available as, an object of classbasic_string[.](#stringbuf.general-1.sentence-2)

[2](#stringbuf.general-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)](#stringbuf.general-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[.](#stringbuf.general-2.1.sentence-1)

- [(2.2)](#stringbuf.general-2.2)

  basic_string<charT, traits, Allocator> *buf* contains the underlying character sequence[.](#stringbuf.general-2.2.sentence-1)

- [(2.3)](#stringbuf.general-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[.](#stringbuf.general-2.3.sentence-1)

#### [31.8.2.2](#stringbuf.cons) Constructors [[stringbuf.cons]](stringbuf.cons)

[ð](#lib:basic_stringbuf,constructor)

`explicit basic_stringbuf(ios_base::openmode which);
`

[1](#stringbuf.cons-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[.](#stringbuf.cons-1.sentence-1)

It isimplementation-defined
whether the sequence pointers
(eback(), gptr(), egptr(),pbase(), pptr(), epptr())
are initialized to null pointers[.](#stringbuf.cons-1.sentence-2)

[2](#stringbuf.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8163)

*Postconditions*: str().empty() is true[.](#stringbuf.cons-2.sentence-1)

[ð](#lib:basic_stringbuf,constructor_)

`explicit basic_stringbuf(
  const basic_string<charT, traits, Allocator>& s,
  ios_base::openmode which = ios_base::in | ios_base::out);
`

[3](#stringbuf.cons-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*()[.](#stringbuf.cons-3.sentence-1)

[ð](#lib:basic_stringbuf,constructor__)

`basic_stringbuf(ios_base::openmode which, const Allocator& a);
`

[4](#stringbuf.cons-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*()[.](#stringbuf.cons-4.sentence-1)

[5](#stringbuf.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8199)

*Postconditions*: str().empty() is true[.](#stringbuf.cons-5.sentence-1)

[ð](#lib:basic_stringbuf,constructor___)

`explicit basic_stringbuf(
  basic_string<charT, traits, Allocator>&& s,
  ios_base::openmode which = ios_base::in | ios_base::out);
`

[6](#stringbuf.cons-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*()[.](#stringbuf.cons-6.sentence-1)

[ð](#lib:basic_stringbuf,constructor____)

`template<class SAlloc>
  basic_stringbuf(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which, const Allocator& a);
`

[7](#stringbuf.cons-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*()[.](#stringbuf.cons-7.sentence-1)

[ð](#lib:basic_stringbuf,constructor_____)

`template<class SAlloc>
  explicit basic_stringbuf(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which = ios_base::in | ios_base::out);
`

[8](#stringbuf.cons-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8246)

*Constraints*: is_same_v<SAlloc, Allocator> is false[.](#stringbuf.cons-8.sentence-1)

[9](#stringbuf.cons-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*()[.](#stringbuf.cons-9.sentence-1)

[ð](#lib:basic_stringbuf,constructor______)

`template<class T>
  explicit basic_stringbuf(const T& t, ios_base::openmode which = ios_base::in | ios_base::out);
template<class T>
  basic_stringbuf(const T& t, const Allocator& a);
template<class T>
  basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a);
`

[10](#stringbuf.cons-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[.](#stringbuf.cons-10.sentence-1)

[11](#stringbuf.cons-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8274)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#stringbuf.cons-11.sentence-1)

[12](#stringbuf.cons-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8279)

*Effects*: Creates a variable sv as if bybasic_string_view<charT, traits> 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*()[.](#stringbuf.cons-12.sentence-1)

[ð](#lib:basic_stringbuf,constructor_______)

`basic_stringbuf(basic_stringbuf&& rhs);
basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a);
`

[13](#stringbuf.cons-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[.](#stringbuf.cons-13.sentence-1)

In the first form buf is initialized
from std​::​move(rhs).str()[.](#stringbuf.cons-13.sentence-2)

In the second form *buf* is initialized
from {std​::​move(rhs).str(), a}[.](#stringbuf.cons-13.sentence-3)

It isimplementation-defined whether the sequence pointers in *this (eback(), gptr(), egptr(),pbase(), pptr(), epptr()) obtain
the values which rhs had[.](#stringbuf.cons-13.sentence-4)

[14](#stringbuf.cons-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[.](#stringbuf.cons-14.sentence-1)

- [(14.1)](#stringbuf.cons-14.1)

str() == rhs_p.str()

- [(14.2)](#stringbuf.cons-14.2)

gptr() - eback() == rhs_p.gptr() - rhs_p.eback()

- [(14.3)](#stringbuf.cons-14.3)

egptr() - eback() == rhs_p.egptr() - rhs_p.eback()

- [(14.4)](#stringbuf.cons-14.4)

pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()

- [(14.5)](#stringbuf.cons-14.5)

epptr() - pbase() == rhs_p.epptr() - rhs_p.pbase()

- [(14.6)](#stringbuf.cons-14.6)

if (eback()) eback() != rhs_a.eback()

- [(14.7)](#stringbuf.cons-14.7)

if (gptr()) gptr() != rhs_a.gptr()

- [(14.8)](#stringbuf.cons-14.8)

if (egptr()) egptr() != rhs_a.egptr()

- [(14.9)](#stringbuf.cons-14.9)

if (pbase()) pbase() != rhs_a.pbase()

- [(14.10)](#stringbuf.cons-14.10)

if (pptr()) pptr() != rhs_a.pptr()

- [(14.11)](#stringbuf.cons-14.11)

if (epptr()) epptr() != rhs_a.epptr()

- [(14.12)](#stringbuf.cons-14.12)

getloc() == rhs_p.getloc()

- [(14.13)](#stringbuf.cons-14.13)

rhs is empty but usable,
 as if std​::​move(rhs).str() was called.

#### [31.8.2.3](#stringbuf.assign) Assignment and swap [[stringbuf.assign]](stringbuf.assign)

[ð](#lib:operator=,basic_stringbuf)

`basic_stringbuf& operator=(basic_stringbuf&& rhs);
`

[1](#stringbuf.assign-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8343)

*Effects*: After the move assignment *this has the observable state it would
have had if it had been move constructed from rhs (see [[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#stringbuf.assign-1.sentence-1)

[2](#stringbuf.assign-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8348)

*Returns*: *this[.](#stringbuf.assign-2.sentence-1)

[ð](#lib:swap,basic_stringbuf)

`void swap(basic_stringbuf& rhs) noexcept(see below);
`

[3](#stringbuf.assign-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8359)

*Preconditions*: allocator_traits<Allocator>​::​propagate_on_container_swap​::​value is true orget_allocator() == rhs.get_allocator() is true[.](#stringbuf.assign-3.sentence-1)

[4](#stringbuf.assign-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8365)

*Effects*: Exchanges the state of *this and rhs[.](#stringbuf.assign-4.sentence-1)

[5](#stringbuf.assign-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8370)

*Remarks*: The exception specification is equivalent to:  

allocator_traits<Allocator>​::​propagate_on_container_swap​::​value ||  

allocator_traits<Allocator>​::​is_always_equal​::​value

[ð](#lib:swap,basic_stringbuf_)

`template<class charT, class traits, class Allocator>
  void swap(basic_stringbuf<charT, traits, Allocator>& x,
            basic_stringbuf<charT, traits, Allocator>& y) noexcept(noexcept(x.swap(y)));
`

[6](#stringbuf.assign-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8385)

*Effects*: Equivalent to x.swap(y)[.](#stringbuf.assign-6.sentence-1)

#### [31.8.2.4](#stringbuf.members) Member functions [[stringbuf.members]](stringbuf.members)

[1](#stringbuf.members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8392)

The member functions getting the underlying character sequence
all refer to a high_mark value,
where high_mark represents the position
one past the highest initialized character in the buffer[.](#stringbuf.members-1.sentence-1)

Characters can be initialized by writing to the stream,
by constructing the basic_stringbuf passing a basic_string argument, or
by calling one of the str member functions
passing a basic_string as an argument[.](#stringbuf.members-1.sentence-2)

In the latter case, all characters initialized prior to the call
are now considered uninitialized
(except for those characters re-initialized by the new basic_string)[.](#stringbuf.members-1.sentence-3)

[ð](#stringbuf.members-itemdecl:1)

`void init-buf-ptrs();
`

[2](#stringbuf.members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8411)

*Effects*: Initializes the input and output sequences from *buf* according to *mode*[.](#stringbuf.members-2.sentence-1)

[3](#stringbuf.members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8416)

*Postconditions*: 

- [(3.1)](#stringbuf.members-3.1)

  If ios_base​::​out is set in *mode*, pbase() points to *buf*.front() and epptr() >= pbase() + *buf*.size() is true;
  * [(3.1.1)](#stringbuf.members-3.1.1)

in addition, if ios_base​::​ate is set in *mode*, pptr() == pbase() + *buf*.size() is true,

  * [(3.1.2)](#stringbuf.members-3.1.2)

otherwise pptr() == pbase() is true[.](#stringbuf.members-3.1.sentence-1)

- [(3.2)](#stringbuf.members-3.2)

  If ios_base​::​in is set in *mode*, eback() points to *buf*.front(), and (gptr() == eback() && egptr() == eback() + *buf*.size()) is true[.](#stringbuf.members-3.2.sentence-1)

[4](#stringbuf.members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8433)

[*Note [1](#stringbuf.members-note-1)*:

For efficiency reasons,
stream buffer operations can violate invariants of *buf* while it is held encapsulated in the basic_stringbuf,
e.g., by writing to characters in the range
[*buf*.data() + *buf*.size(), *buf*.data() + *buf*.capacity())[.](#stringbuf.members-4.sentence-1)

All operations retrieving a basic_string from buf ensure that the basic_string invariants hold on the returned value[.](#stringbuf.members-4.sentence-2)

â *end note*]

[ð](#lib:get_allocator,basic_stringbuf)

`allocator_type get_allocator() const noexcept;
`

[5](#stringbuf.members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8451)

*Returns*: *buf*.get_allocator()[.](#stringbuf.members-5.sentence-1)

[ð](#lib:str,basic_stringbuf)

`basic_string<charT, traits, Allocator> str() const &;
`

[6](#stringbuf.members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8462)

*Effects*: Equivalent to:return basic_string<charT, traits, Allocator>(view(), get_allocator());

[ð](#lib:str,basic_stringbuf_)

`template<class SAlloc>
  basic_string<charT, traits, SAlloc> str(const SAlloc& sa) const;
`

[7](#stringbuf.members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8477)

*Constraints*: SAlloc is a type that
qualifies as an allocator ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements"))[.](#stringbuf.members-7.sentence-1)

[8](#stringbuf.members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8482)

*Effects*: Equivalent to:return basic_string<charT, traits, SAlloc>(view(), sa);

[ð](#stringbuf.members-itemdecl:5)

`basic_string<charT, traits, Allocator> str() &&;
`

[9](#stringbuf.members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8495)

*Postconditions*: The underlying character sequence buf is empty andpbase(), pptr(), epptr(), eback(),gptr(), and egptr() are initialized as if by calling *init-buf-ptrs*() with an empty buf[.](#stringbuf.members-9.sentence-1)

[10](#stringbuf.members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8503)

*Returns*: A basic_string<charT, traits, Allocator> object
move constructed from
the basic_stringbuf's underlying character sequence in buf[.](#stringbuf.members-10.sentence-1)

This can be achieved by first adjusting buf to have
the same content as view()[.](#stringbuf.members-10.sentence-2)

[ð](#lib:view,basic_stringbuf)

`basic_string_view<charT, traits> view() const noexcept;
`

[11](#stringbuf.members-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8518)

Let sv be basic_string_view<charT, traits>[.](#stringbuf.members-11.sentence-1)

[12](#stringbuf.members-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8521)

*Returns*: A sv object referring to
the basic_stringbuf's underlying character sequence in buf:

- [(12.1)](#stringbuf.members-12.1)

  If ios_base​::​out is set in *mode*,
 then sv(pbase(), high_mark - pbase()) is returned[.](#stringbuf.members-12.1.sentence-1)

- [(12.2)](#stringbuf.members-12.2)

  Otherwise, if ios_base​::​in is set in *mode*,
 then sv(eback(), egptr() - eback()) is returned[.](#stringbuf.members-12.2.sentence-1)

- [(12.3)](#stringbuf.members-12.3)

  Otherwise, sv() is returned[.](#stringbuf.members-12.3.sentence-1)

[13](#stringbuf.members-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8533)

[*Note [2](#stringbuf.members-note-2)*:

Using the returned sv object after
destruction or invalidation of the character sequence underlying *this is undefined behavior, unless sv.empty() is true[.](#stringbuf.members-13.sentence-1)

â *end note*]

[ð](#lib:str,basic_stringbuf__)

`void str(const basic_string<charT, traits, Allocator>& s);
`

[14](#stringbuf.members-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8547)

*Effects*: Equivalent to:*buf* = s;*init-buf-ptrs*();

[ð](#lib:str,basic_stringbuf___)

`template<class SAlloc>
  void str(const basic_string<charT, traits, SAlloc>& s);
`

[15](#stringbuf.members-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8563)

*Constraints*: is_same_v<SAlloc, Allocator> is false[.](#stringbuf.members-15.sentence-1)

[16](#stringbuf.members-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8567)

*Effects*: Equivalent to:*buf* = s;*init-buf-ptrs*();

[ð](#lib:str,basic_stringbuf____)

`void str(basic_string<charT, traits, Allocator>&& s);
`

[17](#stringbuf.members-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8582)

*Effects*: Equivalent to:*buf* = std::move(s);*init-buf-ptrs*();

[ð](#lib:str,basic_stringbuf_____)

`template<class T>
  void str(const T& t);
`

[18](#stringbuf.members-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8598)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#stringbuf.members-18.sentence-1)

[19](#stringbuf.members-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8603)

*Effects*: Equivalent to:basic_string_view<charT, traits> sv = t;*buf* = sv;*init-buf-ptrs*();

#### [31.8.2.5](#stringbuf.virtuals) Overridden virtual functions [[stringbuf.virtuals]](stringbuf.virtuals)

[ð](#lib:underflow,basic_stringbuf)

`int_type underflow() override;
`

[1](#stringbuf.virtuals-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8621)

*Returns*: If the input sequence has a read position available,
returnstraits​::​to_int_type(*gptr())[.](#stringbuf.virtuals-1.sentence-1)

Otherwise, returnstraits​::​eof()[.](#stringbuf.virtuals-1.sentence-2)

Any character in the underlying buffer which has been initialized is considered
to be part of the input sequence[.](#stringbuf.virtuals-1.sentence-3)

[ð](#lib:pbackfail,basic_stringbuf)

`int_type pbackfail(int_type c = traits::eof()) override;
`

[2](#stringbuf.virtuals-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8638)

*Effects*: Puts back the character designated by c to the input
sequence, if possible, in one of three ways:

- [(2.1)](#stringbuf.virtuals-2.1)

  Iftraits​::​eq_int_type(c, traits​::​eof()) returnsfalse and
if the input sequence has a putback position available, and
iftraits​::​eq(to_char_type(c), gptr()[-1]) returnstrue,
assignsgptr() - 1 togptr()[.](#stringbuf.virtuals-2.1.sentence-1)
  Returns:c[.](#stringbuf.virtuals-2.1.sentence-2)

- [(2.2)](#stringbuf.virtuals-2.2)

  Iftraits​::​eq_int_type(c, traits​::​eof()) returnsfalse and if the input sequence
has a putback position available, and
if *mode*&ios_base​::​out is
nonzero,
assigns c to*--gptr()[.](#stringbuf.virtuals-2.2.sentence-1)
  Returns:c[.](#stringbuf.virtuals-2.2.sentence-2)

- [(2.3)](#stringbuf.virtuals-2.3)

  Iftraits​::​eq_int_type(c, traits​::​eof()) returnstrue and if the input sequence has a putback position available,
assignsgptr() - 1 togptr()[.](#stringbuf.virtuals-2.3.sentence-1)
  Returns:traits​::​not_eof(c)[.](#stringbuf.virtuals-2.3.sentence-2)

[3](#stringbuf.virtuals-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8692)

*Returns*: As specified above, ortraits​::​eof() to indicate failure[.](#stringbuf.virtuals-3.sentence-1)

[4](#stringbuf.virtuals-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8698)

*Remarks*: If the function can succeed in more than one of these ways, it is
unspecified which way is chosen[.](#stringbuf.virtuals-4.sentence-1)

[ð](#lib:overflow,basic_stringbuf)

`int_type overflow(int_type c = traits::eof()) override;
`

[5](#stringbuf.virtuals-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8711)

*Effects*: Appends the character designated by c to the output
sequence, if possible, in one of two ways:

- [(5.1)](#stringbuf.virtuals-5.1)

  Iftraits​::​eq_int_type(c, traits​::​eof()) returnsfalse and if either
the output sequence has a write position available or
the function makes a write position available
(as described below),
the function callssputc(c)[.](#stringbuf.virtuals-5.1.sentence-1)
  Signals success by returning c[.](#stringbuf.virtuals-5.1.sentence-2)

- [(5.2)](#stringbuf.virtuals-5.2)

  Iftraits​::​eq_int_type(c, traits​::​eof()) returnstrue,
there is no character to append[.](#stringbuf.virtuals-5.2.sentence-1)
  Signals success by returning a value other thantraits​::​eof()[.](#stringbuf.virtuals-5.2.sentence-2)

[6](#stringbuf.virtuals-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8741)

*Returns*: As specified above, ortraits​::​eof() to indicate failure[.](#stringbuf.virtuals-6.sentence-1)

[7](#stringbuf.virtuals-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8747)

*Remarks*: The function can alter the number of write positions available as a
result of any call[.](#stringbuf.virtuals-7.sentence-1)

[8](#stringbuf.virtuals-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8752)

The function can make a write position available only ifios_base​::​out is set in *mode*[.](#stringbuf.virtuals-8.sentence-1)

To make a write position available,
the function reallocates (or initially allocates) an array object
with a sufficient number of elements to hold
the current array object (if any), plus
at least
one additional write position[.](#stringbuf.virtuals-8.sentence-2)

If ios_base​::​in is set in *mode*,
the function alters the read end pointeregptr() to point just past the new write position[.](#stringbuf.virtuals-8.sentence-3)

[ð](#lib:seekoff,basic_stringbuf)

`pos_type seekoff(off_type off, ios_base::seekdir way,
                 ios_base::openmode which
                   = ios_base::in | ios_base::out) override;
`

[9](#stringbuf.virtuals-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8775)

*Effects*: Alters the stream position within one of the
controlled sequences, if possible, as indicated in Table [144](#tab:stringbuf.seekoff.pos "Table 144: seekoff positioning")[.](#stringbuf.virtuals-9.sentence-1)

Table [144](#tab:stringbuf.seekoff.pos) — seekoff positioning [[tab:stringbuf.seekoff.pos]](./tab:stringbuf.seekoff.pos)  

| [ð](#tab:stringbuf.seekoff.pos-row-1)<br>**Conditions** | **Result** |
| --- | --- |
| [ð](#tab:stringbuf.seekoff.pos-row-2)<br>ios_base​::​in is set in which | positions the input sequence |
| [ð](#tab:stringbuf.seekoff.pos-row-3)<br>ios_base​::​out is set in which | positions the output sequence |
| [ð](#tab:stringbuf.seekoff.pos-row-4)<br>both ios_base​::​in and ios_base​::​out are set in which and either   way == ios_base​::​beg or   way == ios_base​::​end | positions both the input and the output sequences |
| [ð](#tab:stringbuf.seekoff.pos-row-5)<br>Otherwise | the positioning operation fails[.](#tab:stringbuf.seekoff.pos-row-5-column-2-sentence-1) |

[10](#stringbuf.virtuals-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8795)

For a sequence to be positioned,
the function determines newoff as indicated in
Table [145](#tab:stringbuf.seekoff.newoff "Table 145: newoff values")[.](#stringbuf.virtuals-10.sentence-1)

If the sequence's next pointer
(eithergptr() orpptr())
is a null pointer and newoff is nonzero,
the positioning operation fails[.](#stringbuf.virtuals-10.sentence-2)

Table [145](#tab:stringbuf.seekoff.newoff) — newoff values [[tab:stringbuf.seekoff.newoff]](./tab:stringbuf.seekoff.newoff)  

| [ð](#tab:stringbuf.seekoff.newoff-row-1)<br>**Condition** | **newoff Value** |
| --- | --- |
| [ð](#tab:stringbuf.seekoff.newoff-row-2)<br>way == ios_base​::​beg | 0 |
| [ð](#tab:stringbuf.seekoff.newoff-row-3)<br>way == ios_base​::​cur | the next pointer minus the beginning pointer (xnext - xbeg)[.](#tab:stringbuf.seekoff.newoff-row-3-column-2-sentence-1) |
| [ð](#tab:stringbuf.seekoff.newoff-row-4)<br>way == ios_base​::​end | the high mark pointer minus the beginning pointer (high_mark - xbeg)[.](#tab:stringbuf.seekoff.newoff-row-4-column-2-sentence-1) |

[11](#stringbuf.virtuals-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8817)

If(newoff + off) < 0,
or if newoff + off refers to an uninitialized
character ([[stringbuf.members]](#stringbuf.members "31.8.2.4 Member functions")),
the positioning operation fails[.](#stringbuf.virtuals-11.sentence-1)

Otherwise, the function assignsxbeg + newoff + off to the next pointer xnext[.](#stringbuf.virtuals-11.sentence-2)

[12](#stringbuf.virtuals-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8827)

*Returns*: pos_type(newoff),
constructed from the resultant offset newoff (of typeoff_type),
that stores the resultant stream position, if possible[.](#stringbuf.virtuals-12.sentence-1)

If the positioning operation fails, or
if the constructed object cannot represent the resultant stream position,
the return value ispos_type(off_type(-1))[.](#stringbuf.virtuals-12.sentence-2)

[ð](#lib:seekpos,basic_stringbuf)

`pos_type seekpos(pos_type sp,
                 ios_base::openmode which
                   = ios_base::in | ios_base::out) override;
`

[13](#stringbuf.virtuals-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8848)

*Effects*: Equivalent to seekoff(off_type(sp), ios_base​::​beg, which)[.](#stringbuf.virtuals-13.sentence-1)

[14](#stringbuf.virtuals-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8852)

*Returns*: sp to indicate success, orpos_type(off_type(-1)) to indicate failure[.](#stringbuf.virtuals-14.sentence-1)

[ð](#lib:setbuf,basic_streambuf)

`basic_streambuf<charT, traits>* setbuf(charT* s, streamsize n) override;
`

[15](#stringbuf.virtuals-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8866)

*Effects*: implementation-defined,
except thatsetbuf(0, 0) has no effect[.](#stringbuf.virtuals-15.sentence-1)

[16](#stringbuf.virtuals-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8873)

*Returns*: this[.](#stringbuf.virtuals-16.sentence-1)

### [31.8.3](#istringstream) Class template basic_istringstream [[istringstream]](istringstream)

#### [31.8.3.1](#istringstream.general) General [[istringstream.general]](istringstream.general)

[ð](#lib:basic_istringstream)

namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_istringstream : public basic_istream<charT, traits> {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; // [[istringstream.cons]](#istringstream.cons "31.8.3.2 Constructors"), constructors basic_istringstream() : basic_istringstream(ios_base::in) {}explicit basic_istringstream(ios_base::openmode which); explicit basic_istringstream(const basic_string<charT, traits, Allocator>& s,
 ios_base::openmode which = ios_base::in);
 basic_istringstream(ios_base::openmode which, const Allocator& a); explicit basic_istringstream( basic_string<charT, traits, Allocator>&& s,
 ios_base::openmode which = ios_base::in); template<class SAlloc> basic_istringstream(const basic_string<charT, traits, SAlloc>& s, const Allocator& a): basic_istringstream(s, ios_base::in, a) {}template<class SAlloc> basic_istringstream(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which, const Allocator& a); template<class SAlloc>explicit basic_istringstream(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which = ios_base::in); template<class T>explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); template<class T> basic_istringstream(const T& t, const Allocator& a); template<class T> basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);
 basic_istringstream(const basic_istringstream&) = delete;
 basic_istringstream(basic_istringstream&& rhs);

 basic_istringstream& operator=(const basic_istringstream&) = delete;
 basic_istringstream& operator=(basic_istringstream&& rhs); // [[istringstream.swap]](#istringstream.swap "31.8.3.3 Swap"), swapvoid swap(basic_istringstream& rhs); // [[istringstream.members]](#istringstream.members "31.8.3.4 Member functions"), members basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
 basic_string<charT, traits, Allocator> str() const &; template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
 basic_string<charT, traits, Allocator> str() &&;
 basic_string_view<charT, traits> view() const noexcept; void str(const basic_string<charT, traits, Allocator>& s); template<class SAlloc>void str(const basic_string<charT, traits, SAlloc>& s); void str(basic_string<charT, traits, Allocator>&& s); template<class T>void str(const T& t); private: basic_stringbuf<charT, traits, Allocator> *sb*; // *exposition only*};}

[1](#istringstream.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8953)

The classbasic_istringstream<charT, traits, Allocator> supports reading objects of classbasic_string<​charT, traits, Allocator>[.](#istringstream.general-1.sentence-1)

It uses abasic_stringbuf<charT, traits, Allocator> object to control the associated storage[.](#istringstream.general-1.sentence-2)

For the sake of exposition, the maintained data is presented here as:

- [(1.1)](#istringstream.general-1.1)

*sb*, the stringbuf object[.](#istringstream.general-1.sentence-3)

#### [31.8.3.2](#istringstream.cons) Constructors [[istringstream.cons]](istringstream.cons)

[ð](#lib:basic_istringstream,constructor)

`explicit basic_istringstream(ios_base::openmode which);
`

[1](#istringstream.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8975)

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_­istream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which | ios_base​::​in) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#istringstream.cons-1.sentence-1)

[ð](#lib:basic_istringstream,constructor_)

`explicit basic_istringstream(
  const basic_string<charT, traits, Allocator>& s,
  ios_base::openmode which = ios_base::in);
`

[2](#istringstream.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8991)

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_­istream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base​::​in)  
 ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#istringstream.cons-2.sentence-1)

[ð](#lib:basic_istringstream,constructor__)

`basic_istringstream(ios_base::openmode which, const Allocator& a);
`

[3](#istringstream.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9005)

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_­istream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which | ios_base​::​in, a) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#istringstream.cons-3.sentence-1)

[ð](#lib:basic_istringstream,constructor___)

`explicit basic_istringstream(
  basic_string<charT, traits, Allocator>&& s,
  ios_base::openmode which = ios_base::in);
`

[4](#istringstream.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9021)

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_­istream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(std​::​move(s), which | ios_base​::​​in) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#istringstream.cons-4.sentence-1)

[ð](#lib:basic_istringstream,constructor____)

`template<class SAlloc>
  basic_istringstream(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which, const Allocator& a);
`

[5](#istringstream.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9038)

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_­istream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base​::​in, a)  
 ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#istringstream.cons-5.sentence-1)

[ð](#lib:basic_istringstream,constructor_____)

`template<class SAlloc>
  explicit basic_istringstream(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which = ios_base::in);
`

[6](#istringstream.cons-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9055)

*Constraints*: is_same_v<SAlloc, Allocator> is false[.](#istringstream.cons-6.sentence-1)

[7](#istringstream.cons-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9059)

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_­istream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base​::​in) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#istringstream.cons-7.sentence-1)

[ð](#lib:basic_istringstream,constructor______)

`template<class T>
  explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in);
template<class T>
  basic_istringstream(const T& t, const Allocator& a);
template<class T>
  basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);
`

[8](#istringstream.cons-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9078)

Let which be ios_base​::​in for the overload with no parameter which, anda be Allocator() for the overload with no parameter a[.](#istringstream.cons-8.sentence-1)

[9](#istringstream.cons-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9083)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#istringstream.cons-9.sentence-1)

[10](#istringstream.cons-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9088)

*Effects*: Initializes the base class with addressof(*sb*), and
direct-non-list-initializes *sb* with t, which | ios_base​::​in, a[.](#istringstream.cons-10.sentence-1)

[ð](#lib:basic_istringstream,constructor_______)

`basic_istringstream(basic_istringstream&& rhs);
`

[11](#istringstream.cons-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9100)

*Effects*: Move constructs from the rvalue rhs[.](#istringstream.cons-11.sentence-1)

This
is accomplished by move constructing the base class, and the containedbasic_stringbuf[.](#istringstream.cons-11.sentence-2)

Then calls basic_istream<charT, traits>​::​set_rdbuf(addressof(*sb*)) to install the contained basic_stringbuf[.](#istringstream.cons-11.sentence-3)

#### [31.8.3.3](#istringstream.swap) Swap [[istringstream.swap]](istringstream.swap)

[ð](#lib:swap,basic_istringstream)

`void swap(basic_istringstream& rhs);
`

[1](#istringstream.swap-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9117)

*Effects*: Equivalent to:basic_istream<charT, traits>::swap(rhs);*sb*.swap(rhs.*sb*);

[ð](#lib:swap,basic_istringstream_)

`template<class charT, class traits, class Allocator>
  void swap(basic_istringstream<charT, traits, Allocator>& x,
            basic_istringstream<charT, traits, Allocator>& y);
`

[2](#istringstream.swap-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9135)

*Effects*: Equivalent to x.swap(y)[.](#istringstream.swap-2.sentence-1)

#### [31.8.3.4](#istringstream.members) Member functions [[istringstream.members]](istringstream.members)

[ð](#lib:rdbuf,basic_istringstream)

`basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
`

[1](#istringstream.members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9148)

*Returns*: const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(*sb*))[.](#istringstream.members-1.sentence-1)

[ð](#lib:str,basic_istringstream)

`basic_string<charT, traits, Allocator> str() const &;
`

[2](#istringstream.members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9159)

*Effects*: Equivalent to: return rdbuf()->str();

[ð](#lib:str,basic_istringstream_)

`template<class SAlloc>
  basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
`

[3](#istringstream.members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9171)

*Effects*: Equivalent to: return rdbuf()->str(sa);

[ð](#lib:str,basic_istringstream__)

`basic_string<charT,traits,Allocator> str() &&;
`

[4](#istringstream.members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9182)

*Effects*: Equivalent to: return std​::​move(*rdbuf()).str();

[ð](#lib:view,basic_istringstream)

`basic_string_view<charT, traits> view() const noexcept;
`

[5](#istringstream.members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9193)

*Effects*: Equivalent to: return rdbuf()->view();

[ð](#lib:str,basic_istringstream___)

`void str(const basic_string<charT, traits, Allocator>& s);
`

[6](#istringstream.members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9204)

*Effects*: Equivalent to: rdbuf()->str(s);

[ð](#lib:str,basic_istringstream____)

`template<class SAlloc>
  void str(const basic_string<charT, traits, SAlloc>& s);
`

[7](#istringstream.members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9216)

*Effects*: Equivalent to: rdbuf()->str(s);

[ð](#lib:str,basic_istringstream_____)

`void str(basic_string<charT, traits, Allocator>&& s);
`

[8](#istringstream.members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9227)

*Effects*: Equivalent to: rdbuf()->str(std​::​move(s));

[ð](#lib:str,basic_istringstream______)

`template<class T>
  void str(const T& t);
`

[9](#istringstream.members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9239)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#istringstream.members-9.sentence-1)

[10](#istringstream.members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9244)

*Effects*: Equivalent to: rdbuf()->str(t);

### [31.8.4](#ostringstream) Class template basic_ostringstream [[ostringstream]](ostringstream)

#### [31.8.4.1](#ostringstream.general) General [[ostringstream.general]](ostringstream.general)

[ð](#lib:basic_ostringstream)

namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_ostringstream : public basic_ostream<charT, traits> {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; // [[ostringstream.cons]](#ostringstream.cons "31.8.4.2 Constructors"), constructors basic_ostringstream() : basic_ostringstream(ios_base::out) {}explicit basic_ostringstream(ios_base::openmode which); explicit basic_ostringstream(const basic_string<charT, traits, Allocator>& s,
 ios_base::openmode which = ios_base::out);
 basic_ostringstream(ios_base::openmode which, const Allocator& a); explicit basic_ostringstream( basic_string<charT, traits, Allocator>&& s,
 ios_base::openmode which = ios_base::out); template<class SAlloc> basic_ostringstream(const basic_string<charT, traits, SAlloc>& s, const Allocator& a): basic_ostringstream(s, ios_base::out, a) {}template<class SAlloc> basic_ostringstream(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which, const Allocator& a); template<class SAlloc>explicit basic_ostringstream(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which = ios_base::out); template<class T>explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); template<class T> basic_ostringstream(const T& t, const Allocator& a); template<class T> basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a);
 basic_ostringstream(const basic_ostringstream&) = delete;
 basic_ostringstream(basic_ostringstream&& rhs);

 basic_ostringstream& operator=(const basic_ostringstream&) = delete;
 basic_ostringstream& operator=(basic_ostringstream&& rhs); // [[ostringstream.swap]](#ostringstream.swap "31.8.4.3 Swap"), swapvoid swap(basic_ostringstream& rhs); // [[ostringstream.members]](#ostringstream.members "31.8.4.4 Member functions"), members basic_stringbuf<charT, traits, Allocator>* rdbuf() const;

 basic_string<charT, traits, Allocator> str() const &; template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
 basic_string<charT, traits, Allocator> str() &&;
 basic_string_view<charT, traits> view() const noexcept; void str(const basic_string<charT, traits, Allocator>& s); template<class SAlloc>void str(const basic_string<charT, traits, SAlloc>& s); void str(basic_string<charT, traits, Allocator>&& s); template<class T>void str(const T& t); private: basic_stringbuf<charT, traits, Allocator> *sb*; // *exposition only*};}

[1](#ostringstream.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9325)

The classbasic_ostringstream<charT, traits, Allocator> supports writing objects of classbasic_string<​charT, traits, Allocator>[.](#ostringstream.general-1.sentence-1)

It uses abasic_stringbuf object to control the associated storage[.](#ostringstream.general-1.sentence-2)

For the sake of exposition, the maintained data is presented here as:

- [(1.1)](#ostringstream.general-1.1)

*sb*, the stringbuf object[.](#ostringstream.general-1.sentence-3)

#### [31.8.4.2](#ostringstream.cons) Constructors [[ostringstream.cons]](ostringstream.cons)

[ð](#lib:basic_ostringstream,constructor)

`explicit basic_ostringstream(ios_base::openmode which);
`

[1](#ostringstream.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9347)

*Effects*: Initializes the base class withbasic_ostream<charT, traits>(addressof(*sb*)) ([[ostream]](ostream "31.7.6.2 Class template basic_­ostream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which | ios_base​::​out) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#ostringstream.cons-1.sentence-1)

[ð](#lib:basic_ostringstream,constructor_)

`explicit basic_ostringstream(
  const basic_string<charT, traits, Allocator>& s,
  ios_base::openmode which = ios_base::out);
`

[2](#ostringstream.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9363)

*Effects*: Initializes the base class withbasic_ostream<charT, traits>(addressof(*sb*)) ([[ostream]](ostream "31.7.6.2 Class template basic_­ostream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base​::​out)  
 ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#ostringstream.cons-2.sentence-1)

[ð](#lib:basic_ostringstream,constructor__)

`basic_ostringstream(ios_base::openmode which, const Allocator& a);
`

[3](#ostringstream.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9377)

*Effects*: Initializes the base class withbasic_ostream<charT, traits>(addressof(*sb*)) ([[ostream]](ostream "31.7.6.2 Class template basic_­ostream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which | ios_base​::​out, a)  
 ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#ostringstream.cons-3.sentence-1)

[ð](#lib:basic_ostringstream,constructor___)

`explicit basic_ostringstream(
  basic_string<charT, traits, Allocator>&& s,
  ios_base::openmode which = ios_base::out);
`

[4](#ostringstream.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9393)

*Effects*: Initializes the base class withbasic_ostream<charT, traits>(addressof(*sb*)) ([[ostream]](ostream "31.7.6.2 Class template basic_­ostream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(std​::​move(s), which | ios_base​::​​out) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#ostringstream.cons-4.sentence-1)

[ð](#lib:basic_ostringstream,constructor____)

`template<class SAlloc>
  basic_ostringstream(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which, const Allocator& a);
`

[5](#ostringstream.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9410)

*Effects*: Initializes the base class withbasic_ostream<charT, traits>(addressof(*sb*)) ([[ostream]](ostream "31.7.6.2 Class template basic_­ostream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base​::​out, a)  
 ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#ostringstream.cons-5.sentence-1)

[ð](#lib:basic_ostringstream,constructor_____)

`template<class SAlloc>
  explicit basic_ostringstream(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which = ios_base::out);
`

[6](#ostringstream.cons-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9427)

*Constraints*: is_same_v<SAlloc, Allocator> is false[.](#ostringstream.cons-6.sentence-1)

[7](#ostringstream.cons-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9431)

*Effects*: Initializes the base class withbasic_ostream<charT, traits>(addressof(*sb*)) ([[ostream]](ostream "31.7.6.2 Class template basic_­ostream"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base​::​out)  
 ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#ostringstream.cons-7.sentence-1)

[ð](#lib:basic_ostringstream,constructor______)

`template<class T>
  explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out);
template<class T>
  basic_ostringstream(const T& t, const Allocator& a);
template<class T>
  basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a);
`

[8](#ostringstream.cons-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9450)

Let which be ios_base​::​out for the overload with no parameter which, anda be Allocator() for the overload with no parameter a[.](#ostringstream.cons-8.sentence-1)

[9](#ostringstream.cons-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9455)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#ostringstream.cons-9.sentence-1)

[10](#ostringstream.cons-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9460)

*Effects*: Initializes the base class with addressof(*sb*), and
direct-non-list-initializes *sb* with t, which | ios_base​::​out, a[.](#ostringstream.cons-10.sentence-1)

[ð](#lib:basic_ostringstream,constructor_______)

`basic_ostringstream(basic_ostringstream&& rhs);
`

[11](#ostringstream.cons-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9472)

*Effects*: Move constructs from the rvalue rhs[.](#ostringstream.cons-11.sentence-1)

This
is accomplished by move constructing the base class, and the containedbasic_stringbuf[.](#ostringstream.cons-11.sentence-2)

Then calls basic_ostream<charT, traits>​::​set_rdbuf(addressof(*sb*)) to install the contained basic_stringbuf[.](#ostringstream.cons-11.sentence-3)

#### [31.8.4.3](#ostringstream.swap) Swap [[ostringstream.swap]](ostringstream.swap)

[ð](#lib:swap,basic_ostringstream)

`void swap(basic_ostringstream& rhs);
`

[1](#ostringstream.swap-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9489)

*Effects*: Equivalent to:basic_ostream<charT, traits>::swap(rhs);*sb*.swap(rhs.*sb*);

[ð](#lib:swap,basic_ostringstream_)

`template<class charT, class traits, class Allocator>
  void swap(basic_ostringstream<charT, traits, Allocator>& x,
            basic_ostringstream<charT, traits, Allocator>& y);
`

[2](#ostringstream.swap-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9506)

*Effects*: Equivalent to x.swap(y)[.](#ostringstream.swap-2.sentence-1)

#### [31.8.4.4](#ostringstream.members) Member functions [[ostringstream.members]](ostringstream.members)

[ð](#lib:rdbuf,basic_ostringstream)

`basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
`

[1](#ostringstream.members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9519)

*Returns*: const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(*sb*))[.](#ostringstream.members-1.sentence-1)

[ð](#lib:str,basic_ostringstream)

`basic_string<charT, traits, Allocator> str() const &;
`

[2](#ostringstream.members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9530)

*Effects*: Equivalent to: return rdbuf()->str();

[ð](#lib:str,basic_ostringstream_)

`template<class SAlloc>
  basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
`

[3](#ostringstream.members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9542)

*Effects*: Equivalent to: return rdbuf()->str(sa);

[ð](#lib:str,basic_ostringstream__)

`basic_string<charT,traits,Allocator> str() &&;
`

[4](#ostringstream.members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9553)

*Effects*: Equivalent to: return std​::​move(*rdbuf()).str();

[ð](#lib:view,basic_ostringstream)

`basic_string_view<charT, traits> view() const noexcept;
`

[5](#ostringstream.members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9564)

*Effects*: Equivalent to: return rdbuf()->view();

[ð](#lib:str,basic_ostringstream___)

`void str(const basic_string<charT, traits, Allocator>& s);
`

[6](#ostringstream.members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9575)

*Effects*: Equivalent to: rdbuf()->str(s);

[ð](#lib:str,basic_ostringstream____)

`template<class SAlloc>
  void str(const basic_string<charT, traits, SAlloc>& s);
`

[7](#ostringstream.members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9587)

*Effects*: Equivalent to: rdbuf()->str(s);

[ð](#lib:str,basic_ostringstream_____)

`void str(basic_string<charT, traits, Allocator>&& s);
`

[8](#ostringstream.members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9598)

*Effects*: Equivalent to: rdbuf()->str(std​::​move(s));

[ð](#lib:str,basic_ostringstream______)

`template<class T>
  void str(const T& t);
`

[9](#ostringstream.members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9610)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#ostringstream.members-9.sentence-1)

[10](#ostringstream.members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9615)

*Effects*: Equivalent to: rdbuf()->str(t);

### [31.8.5](#stringstream) Class template basic_stringstream [[stringstream]](stringstream)

#### [31.8.5.1](#stringstream.general) General [[stringstream.general]](stringstream.general)

[ð](#lib:basic_stringstream)

namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_stringstream : public basic_iostream<charT, traits> {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; // [[stringstream.cons]](#stringstream.cons "31.8.5.2 Constructors"), constructors basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {}explicit basic_stringstream(ios_base::openmode which); explicit basic_stringstream(const basic_string<charT, traits, Allocator>& s,
 ios_base::openmode which = ios_base::out | ios_base::in);
 basic_stringstream(ios_base::openmode which, const Allocator& a); explicit basic_stringstream( basic_string<charT, traits, Allocator>&& s,
 ios_base::openmode which = ios_base::out | ios_base::in); template<class SAlloc> basic_stringstream(const basic_string<charT, traits, SAlloc>& s, const Allocator& a): basic_stringstream(s, ios_base::out | ios_base::in, a) {}template<class SAlloc> basic_stringstream(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which, const Allocator& a); template<class SAlloc>explicit basic_stringstream(const basic_string<charT, traits, SAlloc>& s,
 ios_base::openmode which = ios_base::out | ios_base::in); template<class T>explicit basic_stringstream(const T& t,
 ios_base::openmode which = ios_base::out | ios_base::in); template<class T> basic_stringstream(const T& t, const Allocator& a); template<class T> basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a);
 basic_stringstream(const basic_stringstream&) = delete;
 basic_stringstream(basic_stringstream&& rhs);

 basic_stringstream& operator=(const basic_stringstream&) = delete;
 basic_stringstream& operator=(basic_stringstream&& rhs); // [[stringstream.swap]](#stringstream.swap "31.8.5.3 Swap"), swapvoid swap(basic_stringstream& rhs); // [[stringstream.members]](#stringstream.members "31.8.5.4 Member functions"), members basic_stringbuf<charT, traits, Allocator>* rdbuf() const;

 basic_string<charT, traits, Allocator> str() const &; template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
 basic_string<charT, traits, Allocator> str() &&;
 basic_string_view<charT, traits> view() const noexcept; void str(const basic_string<charT, traits, Allocator>& s); template<class SAlloc>void str(const basic_string<charT, traits, SAlloc>& s); void str(basic_string<charT, traits, Allocator>&& s); template<class T>void str(const T& t); private: basic_stringbuf<charT, traits, Allocator> *sb*; // *exposition only*};}

[1](#stringstream.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9697)

The
class templatebasic_stringstream<charT, traits> supports reading and writing from objects of classbasic_string<charT, traits, Allocator>[.](#stringstream.general-1.sentence-1)

It uses abasic_stringbuf<charT, traits, Allocator> object to control the associated sequence[.](#stringstream.general-1.sentence-2)

For the sake of exposition, the maintained data is presented here as

- [(1.1)](#stringstream.general-1.1)

*sb*, the stringbuf object[.](#stringstream.general-1.sentence-3)

#### [31.8.5.2](#stringstream.cons) Constructors [[stringstream.cons]](stringstream.cons)

[ð](#lib:basic_stringstream,constructor)

`explicit basic_stringstream(ios_base::openmode which);
`

[1](#stringstream.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9720)

*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) ([[iostream.cons]](iostream.cons "31.7.5.7.2 Constructors"))
and*sb* withbasic_stringbuf<charT, traits, Allocator>(which)[.](#stringstream.cons-1.sentence-1)

[ð](#lib:basic_stringstream,constructor_)

`explicit basic_stringstream(
  const basic_string<charT, traits, Allocator>& s,
  ios_base::openmode which = ios_base::out | ios_base::in);
`

[2](#stringstream.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9738)

*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) ([[iostream.cons]](iostream.cons "31.7.5.7.2 Constructors"))
and*sb* withbasic_stringbuf<charT, traits, Allocator>(s, which)[.](#stringstream.cons-2.sentence-1)

[ð](#lib:basic_stringstream,constructor__)

`basic_stringstream(ios_base::openmode which, const Allocator& a);
`

[3](#stringstream.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9754)

*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) ([[iostream.cons]](iostream.cons "31.7.5.7.2 Constructors"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which, a) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#stringstream.cons-3.sentence-1)

[ð](#lib:basic_stringstream,constructor___)

`explicit basic_stringstream(
  basic_string<charT, traits, Allocator>&& s,
  ios_base::openmode which = ios_base::out | ios_base::in);
`

[4](#stringstream.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9770)

*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) ([[iostream.cons]](iostream.cons "31.7.5.7.2 Constructors"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(std​::​move(s), which) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#stringstream.cons-4.sentence-1)

[ð](#lib:basic_stringstream,constructor____)

`template<class SAlloc>
  basic_stringstream(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which, const Allocator& a);
`

[5](#stringstream.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9787)

*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) ([[iostream.cons]](iostream.cons "31.7.5.7.2 Constructors"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which, a) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#stringstream.cons-5.sentence-1)

[ð](#lib:basic_stringstream,constructor_____)

`template<class SAlloc>
  explicit basic_stringstream(
    const basic_string<charT, traits, SAlloc>& s,
    ios_base::openmode which = ios_base::out | ios_base::in);
`

[6](#stringstream.cons-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9804)

*Constraints*: is_same_v<SAlloc, Allocator> is false[.](#stringstream.cons-6.sentence-1)

[7](#stringstream.cons-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9808)

*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) ([[iostream.cons]](iostream.cons "31.7.5.7.2 Constructors"))
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which) ([[stringbuf.cons]](#stringbuf.cons "31.8.2.2 Constructors"))[.](#stringstream.cons-7.sentence-1)

[ð](#lib:basic_stringstream,constructor______)

`template<class T>
  explicit basic_stringstream(const T& t, ios_base::openmode which = ios_base::out | ios_base::in);
template<class T>
  basic_stringstream(const T& t, const Allocator& a);
template<class T>
  basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a);
`

[8](#stringstream.cons-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9827)

Let which be ios_base​::​out | ios_base​::​in for the overload with no parameter which, anda be Allocator() for the overload with no parameter a[.](#stringstream.cons-8.sentence-1)

[9](#stringstream.cons-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9832)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#stringstream.cons-9.sentence-1)

[10](#stringstream.cons-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9837)

*Effects*: Initializes the base class with addressof(*sb*), and
direct-non-list-initializes *sb* with t, which, a[.](#stringstream.cons-10.sentence-1)

[ð](#lib:basic_stringstream,constructor_______)

`basic_stringstream(basic_stringstream&& rhs);
`

[11](#stringstream.cons-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9849)

*Effects*: Move constructs from the rvalue rhs[.](#stringstream.cons-11.sentence-1)

This
is accomplished by move constructing the base class, and the containedbasic_stringbuf[.](#stringstream.cons-11.sentence-2)

Then calls basic_istream<charT, traits>​::​set_rdbuf(addressof(*sb*)) to install the contained basic_stringbuf[.](#stringstream.cons-11.sentence-3)

#### [31.8.5.3](#stringstream.swap) Swap [[stringstream.swap]](stringstream.swap)

[ð](#lib:swap,basic_stringstream)

`void swap(basic_stringstream& rhs);
`

[1](#stringstream.swap-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9866)

*Effects*: Equivalent to:basic_iostream<charT,traits>::swap(rhs);*sb*.swap(rhs.*sb*);

[ð](#lib:swap,basic_stringstream_)

`template<class charT, class traits, class Allocator>
  void swap(basic_stringstream<charT, traits, Allocator>& x,
            basic_stringstream<charT, traits, Allocator>& y);
`

[2](#stringstream.swap-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9883)

*Effects*: Equivalent to x.swap(y)[.](#stringstream.swap-2.sentence-1)

#### [31.8.5.4](#stringstream.members) Member functions [[stringstream.members]](stringstream.members)

[ð](#lib:rdbuf,basic_stringstream)

`basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
`

[1](#stringstream.members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9896)

*Returns*: const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(*sb*))[.](#stringstream.members-1.sentence-1)

[ð](#lib:str,basic_stringstream)

`basic_string<charT, traits, Allocator> str() const &;
`

[2](#stringstream.members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9907)

*Effects*: Equivalent to: return rdbuf()->str();

[ð](#lib:str,basic_stringstream_)

`template<class SAlloc>
  basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
`

[3](#stringstream.members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9919)

*Effects*: Equivalent to: return rdbuf()->str(sa);

[ð](#lib:str,basic_stringstream__)

`basic_string<charT,traits,Allocator> str() &&;
`

[4](#stringstream.members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9930)

*Effects*: Equivalent to: return std​::​move(*rdbuf()).str();

[ð](#lib:view,basic_stringstream)

`basic_string_view<charT, traits> view() const noexcept;
`

[5](#stringstream.members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9941)

*Effects*: Equivalent to: return rdbuf()->view();

[ð](#lib:str,basic_stringstream___)

`void str(const basic_string<charT, traits, Allocator>& s);
`

[6](#stringstream.members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9952)

*Effects*: Equivalent to: rdbuf()->str(s);

[ð](#lib:str,basic_stringstream____)

`template<class SAlloc>
  void str(const basic_string<charT, traits, SAlloc>& s);
`

[7](#stringstream.members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9964)

*Effects*: Equivalent to: rdbuf()->str(s);

[ð](#lib:str,basic_stringstream_____)

`void str(basic_string<charT, traits, Allocator>&& s);
`

[8](#stringstream.members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9975)

*Effects*: Equivalent to: rdbuf()->str(std​::​move(s));

[ð](#lib:str,basic_stringstream______)

`template<class T>
  void str(const T& t);
`

[9](#stringstream.members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9987)

*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#stringstream.members-9.sentence-1)

[10](#stringstream.members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9992)

*Effects*: Equivalent to: rdbuf()->str(t);
