Files
2025-10-25 03:02:53 +03:00

19 KiB
Raw Permalink Blame History

[ios]

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>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; // [iostate.flags], flags functionsexplicit 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); // [basic.ios.cons], constructor/destructorexplicit basic_ios(basic_streambuf<charT, traits>* sb); virtual ~basic_ios(); // [basic.ios.members], members 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);

1

#

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

🔗

basic_ios();

2

#

Effects: Leaves its member objects uninitialized.

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

🔗

~basic_ios();

3

#

Remarks: The destructor does not destroyrdbuf().

🔗

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

4

#

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

Table 142 — 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
🔗
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;

1

#

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

🔗

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

2

#

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

3

#

Postconditions: tiestr == tie().

4

#

Returns: The previous value oftie().

🔗

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

5

#

Returns: A pointer to thestreambuf associated with the stream.

🔗

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

6

#

Effects: Callsclear().

7

#

Postconditions: sb == rdbuf().

8

#

Returns: The previous value ofrdbuf().

🔗

locale imbue(const locale& loc);

9

#

Effects: Callsios_base::imbue(loc) and ifrdbuf() != 0 thenrdbuf()->pubimbue(loc).

10

#

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

🔗

char narrow(char_type c, char dfault) const;

11

#

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

🔗

char_type widen(char c) const;

12

#

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

🔗

char_type fill() const;

13

#

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

🔗

char_type fill(char_type fillch);

14

#

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

15

#

Returns: The previous value offill().

🔗

basic_ios& copyfmt(const basic_ios& rhs);

16

#

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

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

calls each registered callback pair (fn, idx) as(*fn)(erase_event, *this, idx);

then, assigns to the member objects of *this the corresponding member objects ofrhs, except that

rdstate(), rdbuf(), and exceptions() are left unchanged;

the contents of arrays pointed at by pword and iword are copied, not the pointers themselves;263 and

if any newly stored pointer values in *this point at objects stored outside the object rhs and those objects are destroyed when rhs is destroyed, the newly stored pointer values are altered to point at newly constructed copies of the objects;

then, calls each callback pair that was copied from rhs as(*fn)(copyfmt_event, *this, idx);

then, calls exceptions(rhs.exceptions()).

17

#

[Note 1:

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

— end note]

18

#

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

Table 143 — 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()

19

#

Returns: *this.

🔗

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

20

#

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;

21

#

Effects: The states of *this and rhs are 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);

22

#

Preconditions: sb != nullptr is true.

23

#

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

24

#

Postconditions: rdbuf() == sb is true.

25

#

Throws: Nothing.

263)263)

This suggests an infinite amount of copying, but the implementation can keep track of the maximum element of the arrays that is nonzero.

31.5.4.4 Flags functions [iostate.flags]

🔗

explicit operator bool() const;

1

#

Returns: !fail().

🔗

bool operator!() const;

2

#

Returns: fail().

🔗

iostate rdstate() const;

3

#

Returns: The error state of the stream buffer.

🔗

void clear(iostate state = goodbit);

4

#

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.

5

#

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

🔗

void setstate(iostate state);

6

#

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

🔗

bool good() const;

7

#

Returns: rdstate() == 0.

🔗

bool eof() const;

8

#

Returns: true ifeofbit is set inrdstate().

🔗

bool fail() const;

9

#

Returns: true iffailbit orbadbit is set inrdstate().264

🔗

bool bad() const;

10

#

Returns: true ifbadbit is set inrdstate().

🔗

iostate exceptions() const;

11

#

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

🔗

void exceptions(iostate except);

12

#

Effects: Callsclear(rdstate()).

13

#

Postconditions: except == exceptions().

264)264)

Checkingbadbit also forfail() is historical practice.