[ios] (original) (raw)

31 Input/output library [input.output]

31.5 Iostreams base classes [iostreams.base]

31.5.4 Class template basic_ios [ios]

31.5.4.1 Overview [ios.overview]

namespace std { template<class charT, class traits = char_traits<charT>> class basic_ios : public ios_base { 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;explicit operator bool() const;bool operator!() const; iostate rdstate() const;void clear(iostate state = goodbit);void setstate(iostate state);bool good() const;bool eof() const;bool fail() const;bool bad() const; iostate exceptions() const;void exceptions(iostate except);explicit basic_ios(basic_streambuf<charT, traits>* sb);virtual ~basic_ios(); basic_ostream<charT, traits>* tie() const; basic_ostream<charT, traits>* tie(basic_ostream<charT, traits>* tiestr); basic_streambuf<charT, traits>* rdbuf() const; basic_streambuf<charT, traits>* rdbuf(basic_streambuf<charT, traits>* sb); basic_ios& copyfmt(const basic_ios& rhs); char_type fill() const; char_type fill(char_type ch); locale imbue(const locale& loc);char narrow(char_type c, char dfault) const; char_type widen(char c) const; basic_ios(const basic_ios&) = delete; basic_ios& operator=(const basic_ios&) = delete;protected: basic_ios();void init(basic_streambuf<charT, traits>* sb);void move(basic_ios& rhs);void move(basic_ios&& rhs);void swap(basic_ios& rhs) noexcept;void set_rdbuf(basic_streambuf<charT, traits>* sb);};}

31.5.4.2 Constructors [basic.ios.cons]

explicit basic_ios(basic_streambuf<charT, traits>* sb);

Effects: Assigns initial values to its member objects by callinginit(sb).

Effects: Leaves its member objects uninitialized.

The object shall be initialized by callingbasic_ios​::​initbefore its first use or before it is destroyed, whichever comes first; otherwise the behavior is undefined.

Remarks: The destructor does not destroyrdbuf().

void init(basic_streambuf<charT, traits>* sb);

Postconditions: The postconditions of this function are indicated in Table 140.

Table 140 — basic_ios​::​init() effects [tab:basic.ios.cons]

🔗Element Value
🔗rdbuf() sb
🔗tie() 0
🔗rdstate() goodbit if sb is not a null pointer, otherwise badbit.
🔗exceptions() goodbit
🔗flags() skipws | dec
🔗width() 0
🔗precision() 6
🔗fill() widen(' ')
🔗getloc() a copy of the value returned by locale()
🔗iarray a null pointer
🔗parray a null pointer

31.5.4.3 Member functions [basic.ios.members]

basic_ostream<charT, traits>* tie() const;

Returns: An output sequence that is_tied_to (synchronized with) the sequence controlled by the stream buffer.

basic_ostream<charT, traits>* tie(basic_ostream<charT, traits>* tiestr);

Preconditions: If tiestr is not null, tiestr is not reachable by traversing the linked list of tied stream objects starting fromtiestr->tie().

Postconditions: tiestr == tie().

Returns: The previous value oftie().

basic_streambuf<charT, traits>* rdbuf() const;

Returns: A pointer to thestreambufassociated with the stream.

basic_streambuf<charT, traits>* rdbuf(basic_streambuf<charT, traits>* sb);

Postconditions: sb == rdbuf().

Returns: The previous value ofrdbuf().

locale imbue(const locale& loc);

Returns: The prior value ofios_base​::​imbue().

char narrow(char_type c, char dfault) const;

Returns: use_facet<ctype<char_type>>(getloc()).narrow(c, dfault)

char_type widen(char c) const;

Returns: use_facet<ctype<char_type>>(getloc()).widen(c)

Returns: The character used to pad (fill) an output conversion to the specified field width.

char_type fill(char_type fillch);

Postconditions: traits​::​eq(fillch, fill()).

Returns: The previous value offill().

basic_ios& copyfmt(const basic_ios& rhs);

Effects: If(this == addressof(rhs)) is truedoes nothing.

Otherwise assigns to the member objects of*thisthe corresponding member objects of rhs as follows:

[Note 1:

The second pass through the callback pairs permits a copied pwordvalue to be zeroed, or to have its referent deep copied or reference counted, or to have other special action taken.

— _end note_]

Postconditions: The postconditions of this function are indicated in Table 141.

Table 141 — basic_ios​::​copyfmt() effects [tab:basic.ios.copyfmt]

🔗Element Value
🔗rdbuf() unchanged
🔗tie() rhs.tie()
🔗rdstate() unchanged
🔗exceptions() rhs.exceptions()
🔗flags() rhs.flags()
🔗width() rhs.width()
🔗precision() rhs.precision()
🔗fill() rhs.fill()
🔗getloc() rhs.getloc()

void move(basic_ios& rhs);void move(basic_ios&& rhs);

Postconditions: *this has the state thatrhs had before the function call, except thatrdbuf() returns nullptr.

rhs is in a valid but unspecified state, except that rhs.rdbuf() returns the same value as it returned before the function call, andrhs.tie() returns nullptr.

void swap(basic_ios& rhs) noexcept;

Effects: The states of *this and rhsare exchanged, except that rdbuf() returns the same value as it returned before the function call, and rhs.rdbuf()returns the same value as it returned before the function call.

void set_rdbuf(basic_streambuf<charT, traits>* sb);

Preconditions: sb != nullptr is true.

Effects: Associates the basic_streambuf object pointed to by sb with this stream without callingclear().

Postconditions: rdbuf() == sb is true.

31.5.4.4 Flags functions [iostate.flags]

explicit operator bool() const;

Returns: The error state of the stream buffer.

void clear(iostate state = goodbit);

Effects: If ((state | (rdbuf() ? goodbit : badbit)) & exceptions()) == 0, returns.

Otherwise, the function throws an object of classios_base​::​failure ([ios.failure]), constructed withimplementation-defined argument values.

Postconditions: Ifrdbuf() != 0thenstate == rdstate(); otherwiserdstate() == (state | ios_base​::​badbit).

void setstate(iostate state);

Effects: Callsclear(rdstate() | state)(which may throwios_base​::​failure ([ios.failure])).

Returns: trueifeofbitis set inrdstate().

Returns: trueiffailbitorbadbitis set inrdstate().265

Returns: trueifbadbitis set inrdstate().

iostate exceptions() const;

Returns: A mask that determines what elements set inrdstate()cause exceptions to be thrown.

void exceptions(iostate except);

Effects: Callsclear(rdstate()).

Postconditions: except == exceptions().