[ios.types]

# 31 Input/output library [[input.output]](./#input.output)

## 31.5 Iostreams base classes [[iostreams.base]](iostreams.base#ios.types)

### 31.5.2 Class ios_base [[ios.base]](ios.base#ios.types)

#### 31.5.2.2 Types [ios.types]

#### [31.5.2.2.1](#ios.failure) Class ios_base​::​failure [[ios.failure]](ios.failure)

[ð](#lib:ios_base::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); };}

[1](#ios.failure-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L919)

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[.](#ios.failure-1.sentence-1)

[*Note [1](#ios.failure-note-1)*:

When ios_base​::​failure is a synonym for another type,
that type needs to provide a nested type failure to emulate the injected-class-name[.](#ios.failure-1.sentence-2)

â *end note*]

The classfailure 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[.](#ios.failure-1.sentence-3)

[2](#ios.failure-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L935)

When throwing ios_base​::​failure exceptions, implementations should provide
values of ec that identify the specific reason for the failure[.](#ios.failure-2.sentence-1)

[*Note [2](#ios.failure-note-2)*:

Errors arising from the operating system would typically be reported assystem_category() errors with an error value of the error number
reported by the operating system[.](#ios.failure-2.sentence-2)

Errors arising from within the stream library would
typically be reported as error_code(io_errc​::​stream,
iostream_category())[.](#ios.failure-2.sentence-3)

â *end note*]

[ð](#lib:ios_base::failure,constructor)

`explicit failure(const string& msg, const error_code& ec = io_errc::stream);
`

[3](#ios.failure-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L952)

*Effects*: Constructs the base class with msg and ec[.](#ios.failure-3.sentence-1)

[ð](#lib:ios_base::failure,constructor_)

`explicit failure(const char* msg, const error_code& ec = io_errc::stream);
`

[4](#ios.failure-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L963)

*Effects*: Constructs the base class with msg and ec[.](#ios.failure-4.sentence-1)

#### [31.5.2.2.2](#ios.fmtflags) Type ios_base​::​fmtflags [[ios.fmtflags]](ios.fmtflags)

[ð](#lib:fmtflags,ios_base)

`using fmtflags = T1;
`

[1](#ios.fmtflags-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L976)

The typefmtflags is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))[.](#ios.fmtflags-1.sentence-1)

Setting its elements has the effects indicated in Table [136](#tab:ios.fmtflags "Table 136: fmtflags effects")[.](#ios.fmtflags-1.sentence-2)

Table [136](#tab:ios.fmtflags) — fmtflags effects [[tab:ios.fmtflags]](./tab:ios.fmtflags)  

| [ð](#tab:ios.fmtflags-row-1)<br>**Element** | **Effect(s) if set** |
| --- | --- |
| [ð](#tab:ios.fmtflags-row-2)<br>boolalpha | insert and extract bool type in alphabetic format |
| [ð](#tab:ios.fmtflags-row-3)<br>dec | converts integer input or generates integer output in decimal base |
| [ð](#tab:ios.fmtflags-row-4)<br>fixed | generate floating-point output in fixed-point notation |
| [ð](#tab:ios.fmtflags-row-5)<br>hex | converts integer input or generates integer output in hexadecimal base |
| [ð](#tab:ios.fmtflags-row-6)<br>internal | adds fill characters at a designated internal point in certain generated output,  or identical to right if no such point is designated |
| [ð](#tab:ios.fmtflags-row-7)<br>left | adds fill characters on the right (final positions) of certain generated output |
| [ð](#tab:ios.fmtflags-row-8)<br>oct | converts integer input or generates integer output in octal base |
| [ð](#tab:ios.fmtflags-row-9)<br>right | adds fill characters on the left (initial positions) of certain generated output |
| [ð](#tab:ios.fmtflags-row-10)<br>scientific | generates floating-point output in scientific notation |
| [ð](#tab:ios.fmtflags-row-11)<br>showbase | generates a prefix indicating the numeric base of generated integer output |
| [ð](#tab:ios.fmtflags-row-12)<br>showpoint | generates a decimal-point character unconditionally in generated floating-point output |
| [ð](#tab:ios.fmtflags-row-13)<br>showpos | generates a + sign in non-negative generated numeric output |
| [ð](#tab:ios.fmtflags-row-14)<br>skipws | skips leading whitespace before certain input operations |
| [ð](#tab:ios.fmtflags-row-15)<br>unitbuf | flushes output after each output operation |
| [ð](#tab:ios.fmtflags-row-16)<br>uppercase | replaces certain lowercase letters with their uppercase equivalents in generated output |

[2](#ios.fmtflags-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1016)

Typefmtflags also defines the constants indicated in Table [137](#tab:ios.fmtflags.const "Table 137: fmtflags constants")[.](#ios.fmtflags-2.sentence-1)

Table [137](#tab:ios.fmtflags.const) — fmtflags constants [[tab:ios.fmtflags.const]](./tab:ios.fmtflags.const)  

| [ð](#tab:ios.fmtflags.const-row-1)<br>**Constant** | **Allowable values** |
| --- | --- |
| [ð](#tab:ios.fmtflags.const-row-2)<br>adjustfield | left | right | internal |
| [ð](#tab:ios.fmtflags.const-row-3)<br>basefield | dec | oct | hex |
| [ð](#tab:ios.fmtflags.const-row-4)<br>floatfield | scientific | fixed |

#### [31.5.2.2.3](#ios.iostate) Type ios_base​::​iostate [[ios.iostate]](ios.iostate)

[ð](#lib:iostate,ios_base)

`using iostate = T2;
`

[1](#ios.iostate-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1039)

The typeiostate is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))
that contains the elements indicated in Table [138](#tab:ios.iostate "Table 138: iostate effects")[.](#ios.iostate-1.sentence-1)

Table [138](#tab:ios.iostate) — iostate effects [[tab:ios.iostate]](./tab:ios.iostate)  

| [ð](#tab:ios.iostate-row-1)<br>**Element** | **Effect(s) if set** |
| --- | --- |
| [ð](#tab:ios.iostate-row-2)<br>badbit | indicates a loss of integrity in an input or output sequence  (such as an irrecoverable read error from a file); |
| [ð](#tab:ios.iostate-row-3)<br>eofbit | indicates that an input operation reached the end of an input sequence; |
| [ð](#tab:ios.iostate-row-4)<br>failbit | indicates that an input operation failed to read the expected characters,  or that an output operation failed to generate the desired characters[.](#tab:ios.iostate-row-4-column-2-sentence-1) |

[2](#ios.iostate-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1056)

Typeiostate also defines the constant:

- [(2.1)](#ios.iostate-2.1)

goodbit,
the value zero[.](#ios.iostate-2.sentence-1)

#### [31.5.2.2.4](#ios.openmode) Type ios_base​::​openmode [[ios.openmode]](ios.openmode)

[ð](#lib:openmode,ios_base)

`using openmode = T3;
`

[1](#ios.openmode-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1075)

The typeopenmode is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))[.](#ios.openmode-1.sentence-1)

It contains the elements indicated in Table [139](#tab:ios.openmode "Table 139: openmode effects")[.](#ios.openmode-1.sentence-2)

Table [139](#tab:ios.openmode) — openmode effects [[tab:ios.openmode]](./tab:ios.openmode)  

| [ð](#tab:ios.openmode-row-1)<br>**Element** | **Effect(s) if set** |
| --- | --- |
| [ð](#tab:ios.openmode-row-2)<br>app | seek to end before each write |
| [ð](#tab:ios.openmode-row-3)<br>ate | open and seek to end immediately after opening |
| [ð](#tab:ios.openmode-row-4)<br>binary | perform input and output in binary mode (as opposed to text mode) |
| [ð](#tab:ios.openmode-row-5)<br>in | open for input |
| [ð](#tab:ios.openmode-row-6)<br>noreplace | open in exclusive mode |
| [ð](#tab:ios.openmode-row-7)<br>out | open for output |
| [ð](#tab:ios.openmode-row-8)<br>trunc | truncate an existing stream when opening |

#### [31.5.2.2.5](#ios.seekdir) Type ios_base​::​seekdir [[ios.seekdir]](ios.seekdir)

[ð](#lib:seekdir,ios_base)

`using seekdir = T4;
`

[1](#ios.seekdir-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1107)

The typeseekdir is an enumerated type ([[enumerated.types]](enumerated.types "16.3.3.3.2 Enumerated types"))
that contains the elements indicated in Table [140](#tab:ios.seekdir "Table 140: seekdir effects")[.](#ios.seekdir-1.sentence-1)

Table [140](#tab:ios.seekdir) — seekdir effects [[tab:ios.seekdir]](./tab:ios.seekdir)  

| [ð](#tab:ios.seekdir-row-1)<br>**Element** | **Meaning** |
| --- | --- |
| [ð](#tab:ios.seekdir-row-2)<br>beg | request a seek (for subsequent input or output) relative to the beginning of the stream |
| [ð](#tab:ios.seekdir-row-3)<br>cur | request a seek relative to the current position within the sequence |
| [ð](#tab:ios.seekdir-row-4)<br>end | request a seek relative to the current end of the sequence |

#### [31.5.2.2.6](#ios.init) Class ios_base​::​Init [[ios.init]](ios.init)

[ð](#lib:ios_base::Init)

namespace std {class ios_base::Init {public: Init();
 Init(const Init&) = default; ~Init();
 Init& operator=(const Init&) = default; };}

[1](#ios.init-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1139)

The class Init describes an object whose construction
ensures the construction of the eight objects declared in[<iostream>](iostream.syn#header:%3ciostream%3e "31.4.1 Header <iostream> synopsis [iostream.syn]") ([[iostream.objects]](iostream.objects "31.4 Standard iostream objects")) that associate file
stream buffers with the standard C streams
provided for by the functions declared in[<cstdio>](cstdio.syn#header:%3ccstdio%3e "31.13.1 Header <cstdio> synopsis [cstdio.syn]")[.](#ios.init-1.sentence-1)

[ð](#lib:ios_base::Init,constructor)

`Init();
`

[2](#ios.init-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1154)

*Effects*: Constructs and initializes the objects cin, cout, cerr,clog, wcin, wcout, wcerr, and wclog if
they have not already been constructed and initialized[.](#ios.init-2.sentence-1)

[ð](#lib:ios_base::Init,destructor)

`~Init();
`

[3](#ios.init-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1167)

*Effects*: If there are no other instances of the class still in existence,
callscout.flush(),cerr.flush(),clog.flush(),wcout.flush(),wcerr.flush(),wclog.flush()[.](#ios.init-3.sentence-1)
