DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

iostream(C++std)


cerr , cin , clog , cout , wcerr , wcin , wclog , wcout - defines the iostreams objects that manipulate the standard streams

Synopsis

   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;
       };

Description

Include the iostreams standard header <iostream> to declare objects that control reading from and writing to the standard streams. This is often the only header you need include to perform input and output from a C++ program.

The objects fall into two groups:

Once you perform certain operations on a stream, such as the standard input, you cannot perform operations of a different orientation on the same stream. Hence, a program cannot operate interchangeably on both cin and wcin, for example.

All the objects declared in this header share a peculiar property -- you can assume they are constructed before any static objects you define, in a translation unit that includes <iostreams>. Equally, you can assume that these objects are not destroyed before the destructors for any such static objects you define. (The output streams are, however, flushed during program termination.) Hence, you can safely read from or write to the standard streams prior to program startup and after program termination.

This guarantee is not universal, however. A static constructor may call a function in another translation unit. The called function cannot assume that the objects declared in this header have been constructed, given the uncertain order in which translation units participate in static construction. To use these objects in such a context, you must first construct an object of class ios_base::Init, as in:

   #include <iostream>
   void marker()
       {    // called by some constructor
       ios_base::Init unused_name;
       cout << "called fun" << endl;
       }

cerr

   extern ostream cerr;

The object controls unbuffered insertions to the standard error output as a byte stream. Once the object is constructed, the expression cerr.flags() & unitbuf is nonzero.

cin

   extern istream cin;

The object controls extractions from the standard input as a byte stream. Once the object is constructed, the call cin.tie() returns &cout.

clog

   extern ostream clog;

The object controls buffered insertions to the standard error output as a byte stream.

cout

   extern ostream cout;

The object controls insertions to the standard output as a byte stream.

wcerr

   extern wostream wcerr;

The object controls unbuffered insertions to the standard error output as a wide stream. Once the object is constructed, the expression wcerr.flags() & unitbuf is nonzero.

wcin

   extern wistream wcin;

The object controls extractions from the standard input as a wide stream. Once the object is constructed, the call wcin.tie() returns &wcout.

wclog

   extern wostream wclog;

The object controls buffered insertions to the standard error output as a wide stream.

wcout

   extern wostream wcout;

The object controls insertions to the standard output as a wide stream.

References

ios(C++std)
18 February 2000
© 2000 The Santa Cruz Operation, Inc. All rights reserved.

Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.