C++ ios_base - init


Advertisements

Description

This is used to construction of an object of this member type, ensures that the standard stream objects (cin, cout, cerr, clog, wcin, wcout, wcerr and wclog) are constructed and properly initialized.

Declaration

Following is the declaration for ios_base::Init.

class Init;

The class maintains an internal static counter with the number of existing objects.

class ios_base::Init {
   static int init_cnt;  
public:
   Init();
   ~Init();
}

Member functionss

Member functions of ios_base init should be like this −

  • Init(); (constructor) Increases the internal static counter by one. If the value of the internal counter was zero, the standard iostream objects are constructed and initialized, if they have not yet been constructed and initialized.

  • ~Init(); (destructor) Decreases the internal static counter by one. If the value of the internal counter reaches zero, the standard output streams are flushed (as if their respective flush members were called). Notice that this does not destroy any of the standard objects, whose duration lasts until program termination.

ios.htm
Advertisements