f78 Operators and Default Streams

Contents|Index|Previous|Next

Operators and Default Streams

The GNU Iostream library, libio, implements the standard input and output facilities for C++. These facilities are roughly analogous (in their purpose and ubiquity, at least) with those defined by the C stdio functions.

Although these definitions come from a library, rather than being part of the core language,” they are sufficiently central to be specified in the latest draft standard for C++.

You can use two operators defined in this library for basic input and output operations. They are familiar from any C++ introductory text-book: << for output, and >> for input. (Think of data flowing in the direction of the “arrows.”)

These operators are often used in conjunction with the following three streams that are open by default.

ostream cout 
Variable 
ostream cin 
Variable 
ostream cerr 
Variable 

Casual use of these operators may be seductive, but—other than in writing throwaway code for your own use—it is not necessarily simpler than managing input and output in any other language. For example, robust code should check the state of the input and output streams between operations (for example, using the method good). See Checking the state of a stream. You may also need to adjust maximum input or output field widths, using manipulators like setw or setprecision.

<< 
Operator on ostream 
>> 
Operator on istream 
0