30 Input/output library [input.output]

30.8 String-based streams [string.streams]

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

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

    // [istringstream.members], members
    basic_stringbuf<charT, traits, Allocator>* rdbuf() const;

    basic_string<charT, traits, Allocator> str() const;
    void str(const basic_string<charT, traits, Allocator>& s);
  private:
    basic_stringbuf<charT, traits, Allocator> sb; // exposition only
  };

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

The class basic_­istringstream<charT, traits, Allocator> supports reading objects of class basic_­string<​charT, traits, Allocator>. It uses a basic_­stringbuf<charT, traits, Allocator> object to control the associated storage. For the sake of exposition, the maintained data is presented here as:

30.8.3.1 basic_­istringstream constructors [istringstream.cons]

explicit basic_istringstream(ios_base::openmode which = ios_base::in);

Effects: Constructs an object of class basic_­istringstream<charT, traits>, initializing the base class with basic_­istream(&sb) and initializing sb with basic_­stringbuf<charT, traits, Allocator>(which | ios_­base​::​in)) ([stringbuf.cons]).

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

Effects: Constructs an object of class basic_­istringstream<charT, traits>, initializing the base class with basic_­istream(&sb) and initializing sb with basic_­stringbuf<charT, traits, Allocator>(str, which | ios_­base​::​in)) ([stringbuf.cons]).

basic_istringstream(basic_istringstream&& 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.3.2 Assign and swap [istringstream.assign]

basic_istringstream& operator=(basic_istringstream&& rhs);

Effects: Move assigns the base and members of *this from the base and corresponding members of rhs.

Returns: *this.

void swap(basic_istringstream& rhs);

Effects: Exchanges the state of *this and rhs by calling basic_­istream<charT, traits>​::​swap(rhs) and sb.swap(rhs.sb).

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

Effects: As if by x.swap(y).

30.8.3.3 Member functions [istringstream.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>& s);

Effects: Calls rdbuf()->str(s).