C++ Stream Classes

Stream in C++:

A stream is a sequence of bytes. It acts either as a source from which the input data can be obtained or as a destination to which the output data can be sent. The source stream that provides data to the program is called Input Stream and the destination stream that receives output from the program is called Output Stream.

In C++, the I/O system contains a hierarchy of classes that are used to define various streams to deal with both the console and disk files. These classes are called stream classes. The stream classes are used for input and output operations with the console unit. These classes are declared in the header file [cpp]iostream[/cpp]. This file should be included in all the programs that communicate with the console unit.

The class [cpp]ios[/cpp] is declared as the virtual base class so that only one copy of its members is inherited by the [cpp]iostream[/cpp]. The class [cpp]ios[/cpp] provides the basic support for formatted and unformatted I/O operations. The class [cpp]istream[/cpp] provides the facilities for formatted and unformatted input while the class [cpp]ostream[/cpp] provides the facilities for formatted output.

The class [cpp]iostream[/cpp] provides the facilities for handling both input and output streams. Three classes namely, [cpp]istream_withassign[/cpp], [cpp]ostream_withassign[/cpp] and [cpp]iostream_withassign[/cpp] is used to add assignment operators to these classes.

Stream Classes for Console Operations:

ios: It contains basic facilities that are used by all other input and output classes. It also contains a pointer to a buffer object (streambuf object). It declares constants and functions that are necessary for handling formatted input and output operations.

istream: It inherits the properties of ios. It declares input functions such as get(), getline() and read(). It contains overloaded extraction operator [cpp]>>[/cpp].

ostream: It inherits the properties of ios. It declares output functions put() and write(). It contains overloaded insertion operator [cpp]<<[/cpp]. iostream: It inherits the properties of ios istream and ostream through multiple inheritances and thus contains all the input and output functions.

streambuf: It provides an interface to physical devices through buffers. It acts as a base for filebuf class used ios files.