What are Streams?
A Stream is simply a sequence of bytes.
Streams of bytes flow from one place to another:
- From a device to memory (input operation)
- From memory to a device (output operation)
- From memory to memory
The bytes may represent:
- Text, Graphics, Audio, Video, Raw data, whatever…
The application must associate meaning with the bytes in the stream.
C++ supplies classes that provide both:
- low-level (unformatted) I/O capabilities
and:
- high-level (formatted) I/O capabilities
Stream Library Header Files
#include <iostream> |
Contains basic information required for all stream I/O operations. It declares the cin, cout, cerr, and clog objects. It provides both formatted and unformatted capabilities. |
#include <iomanip> |
Contains information for performing formatted I/O with parameterized stream manipulators. |
#include <fstream> |
Contains information for user-controlled file processing operations. |
#include <strstream> |
Contains information for performing in-memory formatting. (Resembles file I/O, but to and from memory rather than files.) |
#include <stdiostream> |
Allows programs to mix the C and C++ I/O styles. |
Stream I/O Classes and Objects
Among other things, basic_iostream contains the classes:
- basic_istream — supports stream input operations
- basic_ostream — supports stream output operations
- basic_iostream — supports both input and output
These classes are derived from the base class basic_ios:

The class basic_ios provides capabilities which all streams can inherit.
cin, cout, cerr, and clog
istream, ostream and iostream are typedefs which provide specializations of basic_istream, basic_ostream and basic_iostream respectively.
They provide support for character input, character output and combined character input and output.
cin is an object of class istream |
connected to the standard input device |
cout is an object of class ostream |
connected to the standard output device |
cerr is an object of class ostream |
connected to the standard error device unbuffered (output appears immediately) |
clog is an object of class ostream |
connected to the standard error device buffered |
C++ File Processing Classes
Also, C++ file processing uses classes basic_ifstream (for file input), basic_ofstream (for file output), and basic_fstream (for file input and output):

There are many more classes than this in the stream I/O class hierarchy, but we’ll just talk about these for now.