Coupon Accepted Successfully!


Stream Classes

C++ streams are based on class and object theory. C++ has number of classes that work with console and file operations. These classes are known as stream classes. Figure shows the stream classes. All these classes are declared in the header file iostream.h. The file iostream.h must be included in the program, if we are using the functions of these classes.

As described in Figure (a) the classes istream and ostream are derived classes of base class ios. The ios class contains member variable object streambuf. The streambuf places the buffer. The member function of streambuf class handles the buffer by providing the facilities to flush clear and pour the buffer. The class iostream is derived from the classes istream and ostream by using multiple inheritance. The ios class is a virtual class and it is present to avoid ambiguity that frequently appears in multiple inheritance. Chapter 11 describes multiple inheritance and virtual classes.

The ios class has an ability to handle formatted and unformatted I/O operations. The istream class gives support for both formatted and unformatted data. The ostream classes handle the formatting of output data. The iostream contains functions of both istream and ostream classes. The classes istream_withassign, ostream_withassign, and iostream_withassign append appropriate assignment operators as shown in Figure (b) Table describes functions/contents of C++ stream classes.

Hierarchy of stream classes

Table: Functions/Contents of C++ Stream Classes




(1) It is an input and output stream class.

(2) It is used to implement a buffer, i.e. it is pointer to a buffer streambuf.

(3) ios maintains the information on the state of streambuf, i.e. good, bad, eof, etc.



(1) istream provides formatted input.

(2) It is used to handle formatted as well as unformatted conversion of character from a streambuf.

(3) The properties of ios are inherited in istream class.

(4) The instance of class does not carry out the actual input.

(5) istream declares functions such as peek(), tellg(), seekg(), getline(), read(), etc.

(6) istream class overloads the ‘>>’ operator.


(1) It is used for general-purpose output.

(2) It is used to declare the output functions such as tellp(), put(), write(), seekp(), etc.

(3) It is the parent of all output stream.

(4) ostream overloads the ‘<<’ operator.


(1) It is used to handle both input and output streams.


(1) It is derived from istream.

(2) It is used for cin input.


(1) It is a bidirectional stream.

Test Your Skills Now!
Take a Quiz now
Reviewer Name