30 Input/output library [input.output]

30.8 String-based streams [string.streams]

30.8.5 Class template basic_­stringstream [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], constructors
    explicit basic_stringstream(
      ios_base::openmode which = ios_base::out | ios_base::in);
    explicit basic_stringstream(
      const basic_string<charT, traits, Allocator>& str,
      ios_base::openmode which = ios_base::out | ios_base::in);
    basic_stringstream(const basic_stringstream& rhs) = delete;
    basic_stringstream(basic_stringstream&& rhs);

    // [stringstream.assign], assign and swap
    basic_stringstream& operator=(const basic_stringstream& rhs) = delete;
    basic_stringstream& operator=(basic_stringstream&& rhs);
    void swap(basic_stringstream& rhs);

    // [stringstream.members], members
    basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
    basic_string<charT, traits, Allocator> str() const;
    void str(const basic_string<charT, traits, Allocator>& str);

  private:
    basic_stringbuf<charT, traits> sb;  // exposition only
  };

  template<class charT, class traits, class Allocator>
    void swap(basic_stringstream<charT, traits, Allocator>& x,
              basic_stringstream<charT, traits, Allocator>& y);
}
The class template basic_­stringstream<charT, traits> supports reading and writing from objects of class basic_­string<charT, traits, Allocator>.
It uses a basic_­stringbuf<charT, traits, Allocator> object to control the associated sequence.
For the sake of exposition, the maintained data is presented here as
  • sb, the stringbuf object.

30.8.5.1 basic_­stringstream constructors [stringstream.cons]

explicit basic_stringstream( ios_base::openmode which = ios_base::out | ios_base::in);
Effects: Constructs an object of class basic_­stringstream<charT, traits>, initializing the base class with basic_­iostream<charT, traits>(&sb) ([iostream.cons]) and initializing sb with basic_­stringbuf<charT, traits, Allocator>(which).
explicit basic_stringstream( const basic_string<charT, traits, Allocator>& str, ios_base::openmode which = ios_base::out | ios_base::in);
Effects: Constructs an object of class basic_­stringstream<charT, traits>, initializing the base class with basic_­iostream<charT, traits>(&sb) ([iostream.cons]) and initializing sb with basic_­stringbuf<charT, traits, Allocator>(str, which).
basic_stringstream(basic_stringstream&& rhs);
Effects: Move constructs from the rvalue rhs.
This is accomplished by move constructing the base class, and the contained basic_­stringbuf.
Next basic_­istream<charT, traits>​::​set_­rdbuf(&sb) is called to install the contained basic_­stringbuf.

30.8.5.2 Assign and swap [stringstream.assign]

basic_stringstream& operator=(basic_stringstream&& rhs);
Effects: Move assigns the base and members of *this from the base and corresponding members of rhs.
Returns: *this.
void swap(basic_stringstream& rhs);
Effects: Exchanges the state of *this and rhs by calling basic_­iostream<charT,traits>​::​swap(rhs) and sb.swap(rhs.sb).
template<class charT, class traits, class Allocator> void swap(basic_stringstream<charT, traits, Allocator>& x, basic_stringstream<charT, traits, Allocator>& y);
Effects: As if by x.swap(y).

30.8.5.3 Member functions [stringstream.members]

basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
Returns: const_­cast<basic_­stringbuf<charT, traits, Allocator>*>(&sb)
basic_string<charT, traits, Allocator> str() const;
Returns: rdbuf()->str().
void str(const basic_string<charT, traits, Allocator>& str);
Effects: Calls rdbuf()->str(str).