This topic consists mainly of examples of the use of parts of the iostream library. It assumes a reasonable familiarity with C++, including such extensions to C as references, operator overloading, and the like. An attempt has been made to create examples that not only illustrate features of the iostream library, but represent good programming style. A programmer who is new to C++ may copy the examples ``cookbook style,'' but cannot be said to have mastered C++ until he or she understands the examples.
Some of the examples are moderately complicated and demonstrate advanced features of the iostream library. These are included so that the document will continue to be useful as an aid even after the programmer has written a few programs using iostreams.
This document is not a complete description of the iostream library. Some classes and members are not described at all. Some are used without complete descriptions. The reader is referred to the iostream man pages for more details.
The declarations for the iostream library exist in several header files. To use any part of it, a program should include iostream.h. Other header files may be needed for other operations. These are mentioned below, but the #include lines are never put in the examples.
The iostream library is divided into two levels. The low level (based on the streambuf class) is responsible for producing and consuming characters. This level is an independent abstraction and may be used without the upper level. This is appropriate when the program is moving characters around without much (or any) formatting operations.
The upper level is responsible for formatting.
There are three significant classes.
are responsible for input and output
They are both derived from class
which contains members
relating to error conditions and the interface to the low level.
A third class,
is derived (multiple inheritance)
It plays only a
minor role in the library. A ``stream class'' is any class derived from istream or ostream.
This topics covers:
The iostream library described here is similar, but not identical, to the iostream library being specified in the upcoming ANSI/ISO C++ language standard.