29 Input/output library [input.output]

29.5 Iostreams base classes [iostreams.base]

29.5.3 Class ios_­base [ios.base]

29.5.3.2 Types [ios.types]

29.5.3.2.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 1:
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 2:
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.2.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.2.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.2.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.2.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.2.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>.
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().