C++ streams classes

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.

stream classes for console in c++

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.
  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise