Q16. Draw console stream class hierarchy and explain its members.
Answer:
Stream Classes
Stream classes are set of classes, whose functionality depends on console file operations. The stream classes are declared in header file “iostream.h”. It is mandatory for a programmer to include this header file, whenever a program is written using the functions supported by these stream classes.
Figure (a): Stream Classes Hierarchy
Figure (a) represents the hierarchy of stream classes.
From the above hierarchical structure it can be inferred that,
(i) ios is the parent class
(ii) istream, ostream are child classes
(iii) iostreambuffer is a member variable object of ios
(iv) The iostream class is a child class of both istream class and ostream class.
The other streams include classes istream_withassign, Ostream_withassign and iostream_withassign. They are used to append the required assignment operators.
Types of Stream Classes
The different stream classes include,
(a) iso
(b) istream
(c) ostream
(d) iostream
(e) istream_withassign
(f) ostream_withassign
(g) iostream_withassign.
(a) ios
ios is an input and output stream class, that performs both formatted and unformatted I/O operations. This class basically is a pointer that points to a buffer iostreambuffer. Moreover, the information related to the state of iostream buffer is maintained by ios stream class.
(b) istream
istream is a derived class of ios stream class which is used to manage both formatted data and unformatted data that is available streambuf object. In addition to that, istream provides input of formatted data properties of istream.
Properties of istream
(i) The istream class overloads the extraction operator (>).
(ii) It declares functions like peek(), tellg(), seekg(), getline(), read().
(c) ostream
ostream is a output stream class derived from ios class. This class handles the formatting of output data and is used to provide general purpose output.
Properties of ostream
(i) The ostream class overloads the insertion operator(<<).
(ii) It declares functions like tellp(), put(), write(), seek().
(d) iostream
iostream is the derived class of istream and ostream and therefore supports all the functions of its base classes. It is an input and output stream that is used to manage both input and output operations.
(e) istream_withassign
istream_withassign is a stream class derived from istream class and is used while providing input using cin object.
(e) ostream_withassign
ostream_withassign is a stream class derived from ostream Class and is used while generating output using cout.
(g) iostream_withassign
iostream_withassign is a combination of both istream_withassign and ostream_withassign and it can be called as bidirectional stream.