C++ STREAM CLASSES
in The C++ programming Input/Output(I/O) system contains a hierarchy of classes that are used to define various streams to deal with both the disk files and console. These all classes are called stream classes. in the below figure, shows the hierarchy of the stream classes used for the input and output(I/O) operations with the console unit.
These classes declared in the headerfile iostream. This file should be included in all the programs that are
communicate with the console unit.
As seen in the Fig, ios is the base class for istream (input stream) ostream( output stream) which are, in turn, base classes for iostream (input/output stream).
The class ios(Input output system) is declared as the virtual base class so that’s why the only one copy of its members are inherited by the iostream.
The class ios(input output system) provides the basic support for formatted and unformatted I/O (Input/output)operations.
in c++ programming the class istream provides the facilities for formatted and unformatted input while the class ostream (through inheritance) gives the facilities only for formatted outputs.
in c++ class iostream provides the facilities for handling both output and input streams.
There are three classes, namely,ostream_withassign, istream_withassign, and iostream_withassign add assignment operators to these classes.
Table 10.1
gives the details of these all classes.
Table 10.1 stream classes for console operations
Class name |
Contents |
ios (General I/O (input output) stream class) |
include basic facilities that are used by all other input and output classes Also contains a pointer to a buffer object (streambuf object)
Declares constants and functions that are necessary for file handling formatted input and output operations |
istream (input stream) |
Inherits the properties of ios Declares input functions such as get() , getline() and read(),Contains overload extraction operator >> |
ostream (output stream) |
Inherits the properties of ios, Declares output functions put() and write(), Contains overloaded insertion operator << |
iostream (input/output stream) |
– Inherits the properties of ios stream and ostream through multiple inheritance thus contains all the input and output functions. |
streambuf |
– Inherits the properties of ios stream and ostream through multiple inheritance thus contains all the input and output functions. |