Files
2025-10-25 03:02:53 +03:00

11 KiB
Raw Permalink Blame History

[iostream.objects]

31 Input/output library [input.output]

31.4 Standard iostream objects [iostream.objects]

31.4.1 Header synopsis [iostream.syn]

🔗

#include // see [ios.syn]#include // see [streambuf.syn]#include // see [istream.syn]#include // 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;}

31.4.2 Overview [iostream.objects.overview]

1

#

In this Clause, the type name FILE refers to the type FILE declared in .

2

#

The header declares objects that associate objects with the standard C streams provided for by the functions declared in, and includes all the headers necessary to use these objects.

The dynamic types of the stream buffers initially associated with these objects are unspecified, but they have the behavior specified forstd::basic_filebuf orstd::basic_filebuf<wchar_t>.

3

#

The objects are constructed and the associations are established at some time prior to or during the first time an object of classios_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.258

4

#

Recommended practice: If it is possible for them to do so, implementations should initialize the objects earlier than required.

5

#

The results of including in a translation unit shall be as if defined an instance of ios_base::Init with static storage duration.

Each C++ library module ([std.modules]) in a hosted implementation shall behave as if it contains an interface unit that defines an unexported ios_base::Init variable with ordered initialization ([basic.start.dynamic]).

[Note 1:

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.

— end note]

6

#

Mixing operations on corresponding wide- and narrow-character streams follows the same semantics as mixing such operations onFILEs, as specified in the C standard library.

7

#

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 2:

Unsynchronized concurrent use of these objects and streams by multiple threads can result in interleaved characters.

— end note]

See also: ISO/IEC 9899:2024, 7.21.2

258)258)

Constructors and destructors for objects with static storage duration can access these objects to read input fromstdin or write output tostdout orstderr.

31.4.3 Narrow stream objects [narrow.stream.objects]

🔗

istream cin;

1

#

The object cin controls input from a stream buffer associated with the object stdin, declared in .

2

#

After the objectcin is initialized,cin.tie() returns&cout.

Its state is otherwise the same as required forbasic_ios::init.

🔗

ostream cout;

3

#

The object cout controls output to a stream buffer associated with the object stdout, declared in .

🔗

ostream cerr;

4

#

The object cerr controls output to a stream buffer associated with the object stderr, declared in .

5

#

After the objectcerr is initialized,cerr.flags() & unitbuf is nonzero and cerr.tie() returns &cout.

Its state is otherwise the same as required forbasic_ios::init.

🔗

ostream clog;

6

#

The object clog controls output to a stream buffer associated with the object stderr, declared in .

31.4.4 Wide stream objects [wide.stream.objects]

🔗

wistream wcin;

1

#

The object wcin controls input from a stream buffer associated with the object stdin, declared in .

2

#

After the objectwcin is initialized,wcin.tie() returns&wcout.

Its state is otherwise the same as required forbasic_ios<wchar_t>::init.

🔗

wostream wcout;

3

#

The object wcout controls output to a stream buffer associated with the object stdout, declared in .

🔗

wostream wcerr;

4

#

The object wcerr controls output to a stream buffer associated with the object stderr, declared in .

5

#

After the objectwcerr is initialized,wcerr.flags() & unitbuf is nonzero and wcerr.tie() returns &wcout.

Its state is otherwise the same as required forbasic_ios<wchar_t>::init.

🔗

wostream wclog;

6

#

The object wclog controls output to a stream buffer associated with the object stderr, declared in .