| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Member functions | ||||
| Formatting | ||||
| Locales | ||||
| Internal extensible array | ||||
| Miscellaneous | ||||
| Member classes | ||||
ios_base::Init | ||||
| Member types | ||||
class Init; | ||
This class is used to ensure that the default C++ streams (std::cin,std::cout, etc.) are properly initialized and destructed. The class tracks how many instances of it are created and initializes the C++ streams when the first instance is constructed as well as flushes the output streams when the last instance is destructed.
The header<iostream> behaves as if it defines (directly or indirectly) an instance ofstd::ios_base::Init with static storage duration: this makes it safe to access the standard I/O streams in the constructors and destructors of static objects withordered initialization (as long as<iostream> is included in the translation unit before these objects were defined).
EachC++ library module in ahosted implementation behaves as if it contains aninterface unit that defines anunexported As a result, the definition of that variable is appearance-ordered before any declaration following the point of importation of a C++ library module. Whether such a definition exists is unobservable by a program that does not reference any of the standard iostream objects. | (since C++23) |
(constructor) | initializes the default C++ streams if they have not been created yet (public member function) |
(destructor) | flushes the default C++ streams if*this is the last instance to be destroyed (public member function) |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 1123 | C++98 | the behaviors of the constructor and the destructor depend on an exposition-only static data member init_cnt | removed the dependency |
| reads from the standard C input streamstdin (global object)[edit] | |
| writes to the standard C output streamstdout (global object)[edit] | |
| writes to the standard C error streamstderr, unbuffered (global object)[edit] | |
| writes to the standard C error streamstderr (global object)[edit] |