29 Input/output library [input.output]

29.5 Iostreams base classes [iostreams.base]

29.5.1 Header <ios> synopsis [ios.syn]

#include <iosfwd>   // see [iosfwd.syn]

namespace std {
  using streamoff  = implementation-defined;
  using streamsize = implementation-defined;
  template<class stateT> class fpos;

  class ios_base;
  template<class charT, class traits = char_traits<charT>>
    class basic_ios;

  // [std.ios.manip], manipulators
  ios_base& boolalpha  (ios_base& str);
  ios_base& noboolalpha(ios_base& str);

  ios_base& showbase   (ios_base& str);
  ios_base& noshowbase (ios_base& str);

  ios_base& showpoint  (ios_base& str);
  ios_base& noshowpoint(ios_base& str);

  ios_base& showpos    (ios_base& str);
  ios_base& noshowpos  (ios_base& str);

  ios_base& skipws     (ios_base& str);
  ios_base& noskipws   (ios_base& str);

  ios_base& uppercase  (ios_base& str);
  ios_base& nouppercase(ios_base& str);

  ios_base& unitbuf    (ios_base& str);
  ios_base& nounitbuf  (ios_base& str);

  // [adjustfield.manip], adjustfield
  ios_base& internal   (ios_base& str);
  ios_base& left       (ios_base& str);
  ios_base& right      (ios_base& str);

  // [basefield.manip], basefield
  ios_base& dec        (ios_base& str);
  ios_base& hex        (ios_base& str);
  ios_base& oct        (ios_base& str);

  // [floatfield.manip], floatfield
  ios_base& fixed      (ios_base& str);
  ios_base& scientific (ios_base& str);
  ios_base& hexfloat   (ios_base& str);
  ios_base& defaultfloat(ios_base& str);

  // [error.reporting], error reporting
  enum class io_errc {
    stream = 1
  };

  template<> struct is_error_code_enum<io_errc> : public true_type { };
  error_code make_error_code(io_errc e) noexcept;
  error_condition make_error_condition(io_errc e) noexcept;
  const error_category& iostream_category() noexcept;
}

29.5.2 Types [stream.types]

using streamoff = implementation-defined;
The type streamoff is a synonym for one of the signed basic integral types of sufficient size to represent the maximum possible file size for the operating system.286
using streamsize = implementation-defined;
The type streamsize is a synonym for one of the signed basic integral types.
It is used to represent the number of characters transferred in an I/O operation, or the size of I/O buffers.287
Typically long long.
⮥
streamsize is used in most places where ISO C would use size_­t.
⮥

29.5.3 Class ios_­base [ios.base]

namespace std {
  class ios_base {
  public:
    class failure;              // see below

    // [ios.fmtflags], fmtflags
    using fmtflags = T1;
    static constexpr fmtflags boolalpha = unspecified;
    static constexpr fmtflags dec = unspecified;
    static constexpr fmtflags fixed = unspecified;
    static constexpr fmtflags hex = unspecified;
    static constexpr fmtflags internal = unspecified;
    static constexpr fmtflags left = unspecified;
    static constexpr fmtflags oct = unspecified;
    static constexpr fmtflags right = unspecified;
    static constexpr fmtflags scientific = unspecified;
    static constexpr fmtflags showbase = unspecified;
    static constexpr fmtflags showpoint = unspecified;
    static constexpr fmtflags showpos = unspecified;
    static constexpr fmtflags skipws = unspecified;
    static constexpr fmtflags unitbuf = unspecified;
    static constexpr fmtflags uppercase = unspecified;
    static constexpr fmtflags adjustfield = see below;
    static constexpr fmtflags basefield = see below;
    static constexpr fmtflags floatfield = see below;

    // [ios.iostate], iostate
    using iostate = T2;
    static constexpr iostate badbit = unspecified;
    static constexpr iostate eofbit = unspecified;
    static constexpr iostate failbit = unspecified;
    static constexpr iostate goodbit = see below;

    // [ios.openmode], openmode
    using openmode = T3;
    static constexpr openmode app = unspecified;
    static constexpr openmode ate = unspecified;
    static constexpr openmode binary = unspecified;
    static constexpr openmode in = unspecified;
    static constexpr openmode out = unspecified;
    static constexpr openmode trunc = unspecified;

    // [ios.seekdir], seekdir
    using seekdir = T4;
    static constexpr seekdir beg = unspecified;
    static constexpr seekdir cur = unspecified;
    static constexpr seekdir end = unspecified;

    class Init;

    // [fmtflags.state], fmtflags state
    fmtflags flags() const;
    fmtflags flags(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl, fmtflags mask);
    void unsetf(fmtflags mask);

    streamsize precision() const;
    streamsize precision(streamsize prec);
    streamsize width() const;
    streamsize width(streamsize wide);

    // [ios.base.locales], locales
    locale imbue(const locale& loc);
    locale getloc() const;

    // [ios.base.storage], storage
    static int xalloc();
    long&  iword(int idx);
    void*& pword(int idx);

    // destructor
    virtual ~ios_base();

    // [ios.base.callback], callbacks
    enum event { erase_event, imbue_event, copyfmt_event };
    using event_callback = void (*)(event, ios_base&, int idx);
    void register_callback(event_callback fn, int idx);

    ios_base(const ios_base&) = delete;
    ios_base& operator=(const ios_base&) = delete;

    static bool sync_with_stdio(bool sync = true);

  protected:
    ios_base();

  private:
    static int index;           // exposition only
    long*  iarray;              // exposition only
    void** parray;              // exposition only
  };
}
ios_­base defines several member types:
  • a type failure, defined as either a class derived from system_­error or a synonym for a class derived from system_­error;
  • a class Init;
  • three bitmask types, fmtflags, iostate, and openmode;
  • an enumerated type, seekdir.
It maintains several kinds of data:
  • state information that reflects the integrity of the stream buffer;
  • control information that influences how to interpret (format) input sequences and how to generate (format) output sequences;
  • additional information that is stored by the program for its private use.
[Note
:
For the sake of exposition, the maintained data is presented here as:
  • static int index, specifies the next available unique index for the integer or pointer arrays maintained for the private use of the program, initialized to an unspecified value;
  • long* iarray, points to the first element of an arbitrary-length long array maintained for the private use of the program;
  • void** parray, points to the first element of an arbitrary-length pointer array maintained for the private use of the program.
— end note
]

29.5.3.1 Types [ios.types]

29.5.3.1.1 Class ios_­base​::​failure [ios.failure]

namespace std {
  class ios_base::failure : public system_error {
  public:
    explicit failure(const string& msg, const error_code& ec = io_errc::stream);
    explicit failure(const char* msg, const error_code& ec = io_errc::stream);
  };
}
An implementation is permitted to define ios_­base​::​failure as a synonym for a class with equivalent functionality to class ios_­base​::​failure shown in this subclause.
[Note
:
When ios_­base​::​failure is a synonym for another type, that type is required to provide a nested type failure to emulate the injected-class-name.
— end note
]
The class failure defines the base class for the types of all objects thrown as exceptions, by functions in the iostreams library, to report errors detected during stream buffer operations.
When throwing ios_­base​::​failure exceptions, implementations should provide values of ec that identify the specific reason for the failure.
[Note
:
Errors arising from the operating system would typically be reported as system_­category() errors with an error value of the error number reported by the operating system.
Errors arising from within the stream library would typically be reported as error_­code(io_­errc​::​stream, iostream_­category()).
— end note
]
explicit failure(const string& msg, const error_code& ec = io_errc::stream);
Effects: Constructs the base class with msg and ec.
explicit failure(const char* msg, const error_code& ec = io_errc::stream);
Effects: Constructs the base class with msg and ec.

29.5.3.1.2 Type ios_­base​::​fmtflags [ios.fmtflags]

using fmtflags = T1;
The type fmtflags is a bitmask type ([bitmask.types]).
Setting its elements has the effects indicated in Table 116.
Table 116: fmtflags effects   [tab:ios.fmtflags]
Element
Effect(s) if set
boolalpha
insert and extract bool type in alphabetic format
dec
converts integer input or generates integer output in decimal base
fixed
generate floating-point output in fixed-point notation
hex
converts integer input or generates integer output in hexadecimal base
internal
adds fill characters at a designated internal point in certain generated output, or identical to right if no such point is designated
left
adds fill characters on the right (final positions) of certain generated output
oct
converts integer input or generates integer output in octal base
right
adds fill characters on the left (initial positions) of certain generated output
scientific
generates floating-point output in scientific notation
showbase
generates a prefix indicating the numeric base of generated integer output
showpoint
generates a decimal-point character unconditionally in generated floating-point output
showpos
generates a + sign in non-negative generated numeric output
skipws
skips leading whitespace before certain input operations
unitbuf
flushes output after each output operation
uppercase
replaces certain lowercase letters with their uppercase equivalents in generated output
Type fmtflags also defines the constants indicated in Table 117.
Table 117: fmtflags constants   [tab:ios.fmtflags.const]
Constant
Allowable values
adjustfield
left | right | internal
basefield
dec | oct | hex
floatfield
scientific | fixed

29.5.3.1.3 Type ios_­base​::​iostate [ios.iostate]

using iostate = T2;
The type iostate is a bitmask type ([bitmask.types]) that contains the elements indicated in Table 118.
Table 118: iostate effects   [tab:ios.iostate]
Element
Effect(s) if set
badbit
indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error from a file);
eofbit
indicates that an input operation reached the end of an input sequence;
failbit
indicates that an input operation failed to read the expected characters, or that an output operation failed to generate the desired characters.
Type iostate also defines the constant:

29.5.3.1.4 Type ios_­base​::​openmode [ios.openmode]

using openmode = T3;
The type openmode is a bitmask type ([bitmask.types]).
It contains the elements indicated in Table 119.
Table 119: openmode effects   [tab:ios.openmode]
Element
Effect(s) if set
app
seek to end before each write
ate
open and seek to end immediately after opening
binary
perform input and output in binary mode (as opposed to text mode)
in
open for input
out
open for output
trunc
truncate an existing stream when opening

29.5.3.1.5 Type ios_­base​::​seekdir [ios.seekdir]

using seekdir = T4;
The type seekdir is an enumerated type ([enumerated.types]) that contains the elements indicated in Table 120.
Table 120: seekdir effects   [tab:ios.seekdir]
Element
Meaning
beg
request a seek (for subsequent input or output) relative to the beginning of the stream
cur
request a seek relative to the current position within the sequence
end
request a seek relative to the current end of the sequence

29.5.3.1.6 Class ios_­base​::​Init [ios.init]

namespace std {
  class ios_base::Init {
  public:
    Init();
    Init(const Init&) = default;
    ~Init();
    Init& operator=(const Init&) = default;
  private:
    static int init_cnt;        // exposition only
  };
}
The class Init describes an object whose construction ensures the construction of the eight objects declared in <iostream> ([iostream.objects]) that associate file stream buffers with the standard C streams provided for by the functions declared in <cstdio> ([cstdio.syn]).
For the sake of exposition, the maintained data is presented here as:
  • static int init_­cnt, counts the number of constructor and destructor calls for class Init, initialized to zero.
Init();
Effects: Constructs and initializes the objects cin, cout, cerr, clog, wcin, wcout, wcerr, and wclog if they have not already been constructed and initialized.
~Init();
Effects: If there are no other instances of the class still in existence, calls cout.flush(), cerr.flush(), clog.flush(), wcout.flush(), wcerr.flush(), wclog.flush().

29.5.3.2 State functions [fmtflags.state]

fmtflags flags() const;
Returns: The format control information for both input and output.
fmtflags flags(fmtflags fmtfl);
Postconditions: fmtfl == flags().
Returns: The previous value of flags().
fmtflags setf(fmtflags fmtfl);
Effects: Sets fmtfl in flags().
Returns: The previous value of flags().
fmtflags setf(fmtflags fmtfl, fmtflags mask);
Effects: Clears mask in flags(), sets fmtfl & mask in flags().
Returns: The previous value of flags().
void unsetf(fmtflags mask);
Effects: Clears mask in flags().
streamsize precision() const;
Returns: The precision to generate on certain output conversions.
streamsize precision(streamsize prec);
Postconditions: prec == precision().
Returns: The previous value of precision().
streamsize width() const;
Returns: The minimum field width (number of characters) to generate on certain output conversions.
streamsize width(streamsize wide);
Postconditions: wide == width().
Returns: The previous value of width().

29.5.3.3 Functions [ios.base.locales]

locale imbue(const locale& loc);
Effects: Calls each registered callback pair (fn, idx) ([ios.base.callback]) as (*fn)(imbue_­event, *this, idx) at such a time that a call to ios_­base​::​getloc() from within fn returns the new locale value loc.
Postconditions: loc == getloc().
Returns: The previous value of getloc().
locale getloc() const;
Returns: If no locale has been imbued, a copy of the global C++ locale, locale(), in effect at the time of construction.
Otherwise, returns the imbued locale, to be used to perform locale-dependent input and output operations.

29.5.3.4 Static members [ios.members.static]

static bool sync_with_stdio(bool sync = true);
Returns: true if the previous state of the standard iostream objects was synchronized and otherwise returns false.
The first time it is called, the function returns true.
Effects: If any input or output operation has occurred using the standard streams prior to the call, the effect is implementation-defined.
Otherwise, called with a false argument, it allows the standard streams to operate independently of the standard C streams.
When a standard iostream object str is synchronized with a standard stdio stream f, the effect of inserting a character c by
fputc(f, c);
is the same as the effect of
str.rdbuf()->sputc(c);
for any sequences of characters; the effect of extracting a character c by
c = fgetc(f);
is the same as the effect of
c = str.rdbuf()->sbumpc();
for any sequences of characters; and the effect of pushing back a character c by
ungetc(c, f);
is the same as the effect of
str.rdbuf()->sputbackc(c);
for any sequence of characters.288
This implies that operations on a standard iostream object can be mixed arbitrarily with operations on the corresponding stdio stream.
In practical terms, synchronization usually means that a standard iostream object and a standard stdio object share a buffer.
⮥

29.5.3.5 Storage functions [ios.base.storage]

static int xalloc();
Returns: index ++.
Remarks: Concurrent access to this function by multiple threads does not result in a data race.
long& iword(int idx);
Preconditions: idx is a value obtained by a call to xalloc.
Effects: If iarray is a null pointer, allocates an array of long of unspecified size and stores a pointer to its first element in iarray.
The function then extends the array pointed at by iarray as necessary to include the element iarray[idx].
Each newly allocated element of the array is initialized to zero.
The reference returned is invalid after any other operations on the object.289
However, the value of the storage referred to is retained, so that until the next call to copyfmt, calling iword with the same index yields another reference to the same value.
If the function fails290 and *this is a base class subobject of a basic_­ios<> object or subobject, the effect is equivalent to calling basic_­ios<>​::​setstate(badbit) on the derived object (which may throw failure).
Returns: On success iarray[idx].
On failure, a valid long& initialized to 0.
void*& pword(int idx);
Preconditions: idx is a value obtained by a call to xalloc.
Effects: If parray is a null pointer, allocates an array of pointers to void of unspecified size and stores a pointer to its first element in parray.
The function then extends the array pointed at by parray as necessary to include the element parray[idx].
Each newly allocated element of the array is initialized to a null pointer.
The reference returned is invalid after any other operations on the object.
However, the value of the storage referred to is retained, so that until the next call to copyfmt, calling pword with the same index yields another reference to the same value.
If the function fails291 and *this is a base class subobject of a basic_­ios<> object or subobject, the effect is equivalent to calling basic_­ios<>​::​setstate(badbit) on the derived object (which may throw failure).
Returns: On success parray[idx].
On failure a valid void*& initialized to 0.
Remarks: After a subsequent call to pword(int) for the same object, the earlier return value may no longer be valid.
An implementation is free to implement both the integer array pointed at by iarray and the pointer array pointed at by parray as sparse data structures, possibly with a one-element cache for each.
⮥
For example, because it cannot allocate space.
⮥
For example, because it cannot allocate space.
⮥

29.5.3.6 Callbacks [ios.base.callback]

void register_callback(event_callback fn, int idx);
Preconditions: The function fn does not throw exceptions.
Effects: Registers the pair (fn, idx) such that during calls to imbue() ([ios.base.locales]), copyfmt(), or ~ios_­base() ([ios.base.cons]), the function fn is called with argument idx.
Functions registered are called when an event occurs, in opposite order of registration.
Functions registered while a callback function is active are not called until the next event.
Remarks: Identical pairs are not merged.
A function registered twice will be called twice.

29.5.3.7 Constructors and destructor [ios.base.cons]

ios_base();
Effects: Each ios_­base member has an indeterminate value after construction.
The object's members shall be initialized by calling basic_­ios​::​init before the object's first use or before it is destroyed, whichever comes first; otherwise the behavior is undefined.
~ios_base();
Effects: Calls each registered callback pair (fn, idx) ([ios.base.callback]) as (*fn)(​erase_­event, *this, idx) at such time that any ios_­base member function called from within fn has well-defined results.

29.5.4 Class template fpos [fpos]

namespace std {
  template<class stateT> class fpos {
  public:
    // [fpos.members], members
    stateT state() const;
    void state(stateT);
  private;
    stateT st;                  // exposition only
  };
}

29.5.4.1 Members [fpos.members]

void state(stateT s);
Effects: Assigns s to st.
stateT state() const;
Returns: Current value of st.

29.5.4.2 Requirements [fpos.operations]

An fpos type specifies file position information.
It holds a state object whose type is equal to the template parameter stateT.
Type stateT shall meet the Cpp17DefaultConstructible (Table 27), Cpp17CopyConstructible (Table 29), Cpp17CopyAssignable (Table 31), and Cpp17Destructible (Table 32) requirements.
If is_­trivially_­copy_­constructible_­v<stateT> is true, then fpos<stateT> has a trivial copy constructor.
If is_­trivially_­copy_­assignable<stateT> is true, then fpos<stateT> has a trivial copy assignment operator.
If is_­trivially_­destructible_­v<stateT> is true, then fpos<stateT> has a trivial destructor.
All specializations of fpos meet the Cpp17DefaultConstructible, Cpp17CopyConstructible, Cpp17CopyAssignable, Cpp17Destructible, and Cpp17EqualityComparable (Table 25) requirements.
In addition, the expressions shown in Table 121 are valid and have the indicated semantics.
In that table,
  • P refers to an instance of fpos,
  • p and q refer to values of type P or const P,
  • pl and ql refer to modifiable lvalues of type P,
  • O refers to type streamoff, and
  • o refers to a value of type streamoff or const streamoff.
Table 121: Position type requirements   [tab:fpos.operations]
Expression
Return type
Operational
Assertion/note
semantics
pre-/post-condition
P(o)
P
converts from offset
Effects: Value-initializes the state object.
P p(o);
P p = o;
Effects: Value-initializes the state object.

Postconditions: p == P(o)
P()
P
P(0)
P p;
P p(0);
O(p)
streamoff
converts to offset
P(O(p)) == p
p != q
convertible to bool
!(p == q)
p + o
P
+ offset
Remarks: With ql = p + o;, then: ql - o == p
pl += o
P&
+= offset
Remarks: With ql = pl; before the +=, then: pl - o == ql
p - o
P
- offset
Remarks: With ql = p - o;, then: ql + o == p
pl -= o
P&
-= offset
Remarks: With ql = pl; before the -=, then: pl + o == ql
o + p
convertible to P
p + o
P(o + p) == p + o
p - q
streamoff
distance
p == q + (p - q)
Stream operations that return a value of type traits​::​pos_­type return P(O(-1)) as an invalid value to signal an error.
If this value is used as an argument to any istream, ostream, or streambuf member that accepts a value of type traits​::​pos_­type then the behavior of that function is undefined.

29.5.5 Class template basic_­ios [ios]

29.5.5.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;

    // [iostate.flags], flags functions
    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);

    // [basic.ios.cons], constructor/destructor
    explicit 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);

  };
}

29.5.5.2 Constructors [basic.ios.cons]

explicit basic_ios(basic_streambuf<charT, traits>* sb);
Effects: Assigns initial values to its member objects by calling init(sb).
basic_ios();
Effects: Leaves its member objects uninitialized.
The object shall be initialized by calling basic_­ios​::​init before its first use or before it is destroyed, whichever comes first; otherwise the behavior is undefined.
~basic_ios();
Remarks: The destructor does not destroy rdbuf().
void init(basic_streambuf<charT, traits>* sb);
Postconditions: The postconditions of this function are indicated in Table 122.
Table 122: 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

29.5.5.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 from tiestr->tie().
Postconditions: tiestr == tie().
Returns: The previous value of tie().
basic_streambuf<charT, traits>* rdbuf() const;
Returns: A pointer to the streambuf associated with the stream.
basic_streambuf<charT, traits>* rdbuf(basic_streambuf<charT, traits>* sb);
Effects: Calls clear().
Postconditions: sb == rdbuf().
Returns: The previous value of rdbuf().
locale imbue(const locale& loc);
Effects: Calls ios_­base​::​imbue(loc) and if rdbuf() != 0 then rdbuf()->pubimbue(loc).
Returns: The prior value of ios_­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)
char_type fill() const;
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 of fill().
basic_ios& copyfmt(const basic_ios& rhs);
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 of rhs, 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;292 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()).
[Note
:
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
]
Postconditions: The postconditions of this function are indicated in Table 123.
Table 123: 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()
Returns: *this.
void move(basic_ios& rhs); void move(basic_ios&& rhs);
Postconditions: *this has the state that rhs had before the function call, except that rdbuf() 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, and rhs.tie() returns nullptr.
void swap(basic_ios& rhs) noexcept;
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);
Preconditions: sb != nullptr is true.
Effects: Associates the basic_­streambuf object pointed to by sb with this stream without calling clear().
Postconditions: rdbuf() == sb is true.
Throws: Nothing.
This suggests an infinite amount of copying, but the implementation can keep track of the maximum element of the arrays that is nonzero.
⮥

29.5.5.4 Flags functions [iostate.flags]

explicit operator bool() const;
Returns: !fail().
bool operator!() const;
Returns: fail().
iostate rdstate() const;
Returns: The error state of the stream buffer.
void clear(iostate state = goodbit);
Postconditions: If rdbuf() != 0 then state == rdstate(); otherwise rdstate() == (state | ios_­base​::​badbit).
Effects: If ((state | (rdbuf() ? goodbit : badbit)) & exceptions()) == 0, returns.
Otherwise, the function throws an object of class ios_­base​::​failure ([ios.failure]), constructed with implementation-defined argument values.
void setstate(iostate state);
Effects: Calls clear(rdstate() | state) (which may throw ios_­base​::​failure ([ios.failure])).
bool good() const;
Returns: rdstate() == 0
bool eof() const;
Returns: true if eofbit is set in rdstate().
bool fail() const;
Returns: true if failbit or badbit is set in rdstate().293
bool bad() const;
Returns: true if badbit is set in rdstate().
iostate exceptions() const;
Returns: A mask that determines what elements set in rdstate() cause exceptions to be thrown.
void exceptions(iostate except);
Postconditions: except == exceptions().
Effects: Calls clear(rdstate()).
Checking badbit also for fail() is historical practice.
⮥

29.5.6 ios_­base manipulators [std.ios.manip]

29.5.6.1 fmtflags manipulators [fmtflags.manip]

Each function specified in this subclause is a designated addressable function ([namespace.std]).
ios_base& boolalpha(ios_base& str);
Effects: Calls str.setf(ios_­base​::​boolalpha).
Returns: str.
ios_base& noboolalpha(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​boolalpha).
Returns: str.
ios_base& showbase(ios_base& str);
Effects: Calls str.setf(ios_­base​::​showbase).
Returns: str.
ios_base& noshowbase(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​showbase).
Returns: str.
ios_base& showpoint(ios_base& str);
Effects: Calls str.setf(ios_­base​::​showpoint).
Returns: str.
ios_base& noshowpoint(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​showpoint).
Returns: str.
ios_base& showpos(ios_base& str);
Effects: Calls str.setf(ios_­base​::​showpos).
Returns: str.
ios_base& noshowpos(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​showpos).
Returns: str.
ios_base& skipws(ios_base& str);
Effects: Calls str.setf(ios_­base​::​skipws).
Returns: str.
ios_base& noskipws(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​skipws).
Returns: str.
ios_base& uppercase(ios_base& str);
Effects: Calls str.setf(ios_­base​::​uppercase).
Returns: str.
ios_base& nouppercase(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​uppercase).
Returns: str.
ios_base& unitbuf(ios_base& str);
Effects: Calls str.setf(ios_­base​::​unitbuf).
Returns: str.
ios_base& nounitbuf(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​unitbuf).
Returns: str.

29.5.6.2 adjustfield manipulators [adjustfield.manip]

Each function specified in this subclause is a designated addressable function ([namespace.std]).
ios_base& internal(ios_base& str);
Effects: Calls str.setf(ios_­base​::​internal, ios_­base​::​adjustfield).
Returns: str.
ios_base& left(ios_base& str);
Effects: Calls str.setf(ios_­base​::​left, ios_­base​::​adjustfield).
Returns: str.
ios_base& right(ios_base& str);
Effects: Calls str.setf(ios_­base​::​right, ios_­base​::​adjustfield).
Returns: str.

29.5.6.3 basefield manipulators [basefield.manip]

Each function specified in this subclause is a designated addressable function ([namespace.std]).
ios_base& dec(ios_base& str);
Effects: Calls str.setf(ios_­base​::​dec, ios_­base​::​basefield).
Returns: str294.
ios_base& hex(ios_base& str);
Effects: Calls str.setf(ios_­base​::​hex, ios_­base​::​basefield).
Returns: str.
ios_base& oct(ios_base& str);
Effects: Calls str.setf(ios_­base​::​oct, ios_­base​::​basefield).
Returns: str.
The function signature dec(ios_­base&) can be called by the function signature basic_­ostream& stream​::​operator<<(ios_­base& (*)(ios_­base&)) to permit expressions of the form cout << dec to change the format flags stored in cout.
⮥

29.5.6.4 floatfield manipulators [floatfield.manip]

Each function specified in this subclause is a designated addressable function ([namespace.std]).
ios_base& fixed(ios_base& str);
Effects: Calls str.setf(ios_­base​::​fixed, ios_­base​::​floatfield).
Returns: str.
ios_base& scientific(ios_base& str);
Effects: Calls str.setf(ios_­base​::​scientific, ios_­base​::​floatfield).
Returns: str.
ios_base& hexfloat(ios_base& str);
Effects: Calls str.setf(ios_­base​::​fixed | ios_­base​::​scientific, ios_­base​::​floatfield).
Returns: str.
[Note
:
The more obvious use of ios_­base​::​hex to specify hexadecimal floating-point format would change the meaning of existing well-defined programs.
C++ 2003 gives no meaning to the combination of fixed and scientific.
— end note
]
ios_base& defaultfloat(ios_base& str);
Effects: Calls str.unsetf(ios_­base​::​floatfield).
Returns: str.

29.5.7 Error reporting [error.reporting]

error_code make_error_code(io_errc e) noexcept;
Returns: error_­code(static_­cast<int>(e), iostream_­category()).
error_condition make_error_condition(io_errc e) noexcept;
Returns: error_­condition(static_­cast<int>(e), iostream_­category()).
const error_category& iostream_category() noexcept;
Returns: A reference to an object of a type derived from class error_­category.
The object's default_­error_­condition and equivalent virtual functions shall behave as specified for the class error_­category.
The object's name virtual function shall return a pointer to the string "iostream".