Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/dinkum_en/ecpp/iostream.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/dinkum_en/ecpp/iostream.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/dinkum_en/ecpp/iostream.html on line 4

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/dinkum_en/ecpp/iostream.html on line 4
[Previous] [Contents] [Next]

<iostream>


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.

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;
    }
        // DECLARATIONS
extern istream cin;
extern ostream cout;
        // END OF DECLARATIONS

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.

cout

extern ostream cout;

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


See also the Table of Contents and the Index.

Copyright © 1992-2002 by P.J. Plauger. All rights reserved.

[Previous] [Contents] [Next]

Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/dinkum_en/ecpp/iostream.html on line 101

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/dinkum_en/ecpp/iostream.html on line 101