c++11 standard template (STL) (std::basic_iostream) (2)

Defined in the header file <istream>
template<

    class CharT,
    class Traits = std::char_traits<CharT>

> class basic_iostream;

Class templates basic_iostreamprovide high-level input/output support on streams. Supported operations include read or write and format. This functionality basic_streambufis provided by the class and implemented on the interface. Buffers are accessed through basic_iosthe class.

inheritance diagram

 

Two specializations are defined for common character types:

defined in the header file<istream>

type definition
iostream basic_iostream<char>
wiostream basic_iostream<wchar_t>

 

member function

construct object

std::basic_iostream<CharT,Traits>::basic_iostream

explicit basic_iostream( std::basic_streambuf<CharT,Traits>* sb );

(1)

basic_iostream( const basic_iostream& other ) = delete;

(2) (since C++11)

protected:
basic_iostream( basic_iostream&& other );

(3) (since C++11)

Constructs a new stream object.

sb1) Initialize with streambuf . The base classes are initialized as basic_istream<CharT,Traits>(sb) and basic_ostream<CharT,Traits>(sb). After calling rdbuf() == sb and gcount() == 0.

2) Copy construction is not allowed.

3) Move constructor: The first base class of move construction basic_istreamis basic_istream<CharT,Traits>(std::move(rhs)); This will continue the move construction and initialize the virtual base class std::basic_ios. The initialization of another base class basic_ostreamis implementation-defined (eg, a protected default constructor that does nothing can be added to std::basic_ostream), since move construction cannot be used rhstwice. This move constructor is protected: it is called by the move constructors of the derived stream classes std::basic_fstream and std::basic_stringstream before they are moved and associated with the stream buffer.

parameter

sb - The streambuf to initialize
other - Another stream to initialize

 

destructor object

std::basic_iostream<CharT,Traits>::~basic_iostream

virtual ~basic_iostream();

Destructs an input/output stream.

Notice

This destructor does not rdbuf()perform any operations on the underlying stream buffer ( ): the destructors of exported streams such as std::basic_fstream and std::basic_stringstream are responsible for calling the stream buffer's destructor.

protected member function

Move assignment to another basic_iostream

std::basic_iostream<CharT,Traits>::operator=

basic_iostream& operator=( const basic_iostream& other ) = delete;

(1)

protected:
basic_iostream& operator=( basic_iostream&& other );

(2) (since C++11)

Assign another stream object.

1) Copy assignment is not allowed.

2) Move assignment to another stream object. Equivalently calls swap(rhs). This move assignment operator is protected: it is invoked by the move assignment operators of the derived stream classes std::basic_stringstream and std::basic_fstream, which know how to properly move the associated stream buffer.

parameter

other - another stream whose state is to be assigned

return value

*this

 

Exchange state with another basic_iostream

std::basic_iostream<CharT,Traits>::swap

protected:
void swap( basic_iostream& other );

(since C++11)

Exchange state with another input/output stream. Equivalently calls basic_istream<CharT,Traits>::swap(other) .

This member function is protected: the swap member function of the exported stream classes std::basic_stringstream and std::basic_fstream knows how to properly swap the associated buffer and calls this function.

parameter

other - another stream to exchange state with

return value

*this

Guess you like

Origin blog.csdn.net/qq_40788199/article/details/131737058