##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::ios_base::Init

From cppreference.com
< cpp‎ | io‎ | ios base

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>` declares (directly or indirectly) an instance of std::ios_base::Init with static storage duration, whose definition is provided by the C++ library: this makes it safe to access the standard I/O streams in the constructors and destructors of static objects (as long as `#include <iostream>` is present in the translation unit)

### [edit] Member functions

(constructor) | if *this is the first instance created, initializes the default C++ streams (public member function)
(destructor) | if *this is the last instance created, flushes the default C++ streams (public member function)

### [edit] See also

cin wcin | reads from the standard C input stream stdin (global object) [edit]
cout wcout | writes to the standard C output stream stdout (global object) [edit]
cerr wcerr | writes to the standard C error stream stderr, unbuffered (global object) [edit]
clog wclog | writes to the standard C error stream stderr (global object) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/ios_base/Init&oldid=66647"