Manage IO Operations in C++

C++ Stream Class

C++ accomplishes input/output operations using concept of stream. A stream is a series of bytes whose value depends on the variable in which it is stored. This way, C++ is able to treat all the input and output operations in a uniform manner. Thus, whether it is reading from a file or from the keyboard, for a C++ program it is simply a stream.

We have used the objects cin and cout (pre-defined in the iostream.h file) for the input and output of data of various types. This has been made possible by overloading the operators >> and << to recognize all the basic C++ types.

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 the output stream. In other words, a program extracts the bytes from an input stream and inserts bytes into an output stream.

c++stream classes
c++stream classes

Stream Classes for Console Operations

Class NameContents
ios (General I/O stream class)Contains basic facilities that are used by all other input and output classes. Also contains a pointer to a buffer object. Declares constants and functions that are necessary for handling formatted input and output functions.
istream (Input stream)Inherits the properties of ios. Declares input functions such as get(), getline() and read() Contains overloaded extraction operator >>
Ostream (output stream)Inherits the properties of ios. Declares output functions such as put() and write() Contains overloaded insertion operator <<
iostream (I/O stream)Inherits the properties of ios, istream and ostream through multiple inheritance and thus contains all the input and output functions.
StreambufProvides an interface to physical devices through buffers. Acts as a base for filebuf class used ios files.
Stream Class for Console operations

Two types of IO Operations are:

  1. Formatted IO Operations
  2. Un-formatted IO Operations

Related posts