stream
can be defined as an entity through which a program can send and retrieve the data.A stream can be divided into various types shown as below.
All the streams that perform input and output operations are included in the header files(<iostream
>, <iomanip
> (or) <fstream
>) and declare them in the program to use it . There are four CPP Input/Output streams.
CPP Input/Output Stream | Description |
---|---|
cin | Input Stream |
cout | Output Stream |
cerr | Output Stream |
clog | Output Stream |
istream
class. cin takes the input from keyboard by using stream extraction operator >>. This stream waits till the input is entered. More than one input in a single statement can also be given. ostream
class. cout gives the output to display screen by using stream insertion operator <<. More than one output in a single statement can also be given.
To see any output on the screen, there are two ways.
ostream
class. cerr connected to error device, gives the output immediately as the data in it is not buffered. clog is also connected to error device, but gives the output with a gap as the data is stored in buffer. It loads the output only when the previous output is erased and the buffer becomes empty.