29 Input/output library [input.output]

29.4 Standard iostream objects [iostream.objects]

29.4.1 Header <iostream> synopsis [iostream.syn]

#include <ios> // see [ios.syn] #include <streambuf> // see [streambuf.syn] #include <istream> // see [istream.syn] #include <ostream> // see [ostream.syn] namespace std { extern istream cin; extern ostream cout; extern ostream cerr; extern ostream clog; extern wistream wcin; extern wostream wcout; extern wostream wcerr; extern wostream wclog; }

29.4.2 Overview [iostream.objects.overview]

In this Clause, the type name FILE refers to the type FILE declared in <cstdio>.
The header <iostream> declares objects that associate objects with the standard C streams provided for by the functions declared in <cstdio>, and includes all the headers necessary to use these objects.
The objects are constructed and the associations are established at some time prior to or during the first time an object of class ios_­base​::​Init is constructed, and in any case before the body of main ([basic.start.main]) begins execution.
The objects are not destroyed during program execution.288
Recommended practice: If it is possible for them to do so, implementations should initialize the objects earlier than required.
The results of including <iostream> in a translation unit shall be as if <iostream> defined an instance of ios_­base​::​Init with static storage duration.
Mixing operations on corresponding wide- and narrow-character streams follows the same semantics as mixing such operations on FILEs, as specified in the C standard library.
Concurrent access to a synchronized ([ios.members.static]) standard iostream object's formatted and unformatted input ([istream]) and output ([ostream]) functions or a standard C stream by multiple threads does not result in a data race ([intro.multithread]).
[Note 1:
Unsynchronized concurrent use of these objects and streams by multiple threads can result in interleaved characters.
— end note]
See also: ISO C 7.21.2
Constructors and destructors for objects with static storage duration can access these objects to read input from stdin or write output to stdout or stderr.
 

29.4.3 Narrow stream objects [narrow.stream.objects]

istream cin;
The object cin controls input from a stream buffer associated with the object stdin, declared in <cstdio>.
After the object cin is initialized, cin.tie() returns &cout.
Its state is otherwise the same as required for basic_­ios<char>​::​init.
ostream cout;
The object cout controls output to a stream buffer associated with the object stdout, declared in <cstdio>.
ostream cerr;
The object cerr controls output to a stream buffer associated with the object stderr, declared in <cstdio>.
After the object cerr is initialized, cerr.flags() & unitbuf is nonzero and cerr.tie() returns &cout.
Its state is otherwise the same as required for basic_­ios<char>​::​init.
ostream clog;
The object clog controls output to a stream buffer associated with the object stderr, declared in <cstdio>.

29.4.4 Wide stream objects [wide.stream.objects]

wistream wcin;
The object wcin controls input from a stream buffer associated with the object stdin, declared in <cstdio>.
After the object wcin is initialized, wcin.tie() returns &wcout.
Its state is otherwise the same as required for basic_­ios<wchar_­t>​::​init.
wostream wcout;
The object wcout controls output to a stream buffer associated with the object stdout, declared in <cstdio>.
wostream wcerr;
The object wcerr controls output to a stream buffer associated with the object stderr, declared in <cstdio>.
After the object wcerr is initialized, wcerr.flags() & unitbuf is nonzero and wcerr.tie() returns &wcout.
Its state is otherwise the same as required for basic_­ios<wchar_­t>​::​init.
wostream wclog;
The object wclog controls output to a stream buffer associated with the object stderr, declared in <cstdio>.