4.2. Stream Classes Hierarchy
Q15. Discuss in brief about streams in C++.
Answer:
Streams in C++
A stream can be defined as an interface between user and I/O devices. The I/O devices such as keyboard, disk, tape driver and monitor provides a source to perform I/O operations which include read and write operations. To perform I/O operations, I/O stream functions are mandatory and these functions are available in standard C++ library.
A standard library contains, .obj files and they are included in the program to perform various I/O operations. These operations provide portability to the program.
A stream can also be defined as flow of data. The flow can be calculated in terms of bytes in sequential manner. There are two types of streams, such as source stream and destination stream. The source stream receives data from the input devices such as keyboard and the data is considered as input data. Therefore, the other name for source Stream is given as input stream. On the otherhand, the destination stream collects data from the program and passes to output devices such as monitor. Therefore, the other name of destination stream is output stream.
Figure: Block Diagram of 1/0 Devices and Streams
Figure: Block Diagram to Represent C++ Input and Output Streams
The input devices such as keyboard or’storage devices (hard disk, floppy disk) pass input data to input stream and output devices such as monitor or printer receive the output data from output stream.