Coupon Accepted Successfully!



With the advancement of information technology, sea information is available on the Internet. A huge amount of data is processed in the computer networking. The information can be uploaded or downloaded from a desktop computer. The information transfer in computer networking in day-to-day life is in the form of files. The files can be written, read, or updated depending on the applications. The data are saved in the file on the disk. The file is an accumulation of data stored on the disk. The stored data can be retrieved or updated. The console I/O function reads data through input devices and displays them on the screen. The data read through these functions are temporarily stored in variables or arrays. The data stored vanishes when the program ends. In order to store the data permanently, we need to apply the disk I/O function. The disk I/O functions are associated with disk files. These functions perform read and write operations with the file. Similar to other languages, C++ also provides functions that allow the programmer to perform read and write operations with the file. The disk I/O functions in C++ are very different as compared with C, though the entire disk I/O functions of C can be used in C++. However, these functions are not appropriate for the object-oriented conditions.
Secondary storage devices such as floppy disks and hard disks are used to store data in the form of files. The main memories of a computer such as random access memory or read-only memory are not used for the storage of files. This is because the main memory of a computer is limited and cannot hold a large amount of data. Another reason is that the main memory is volatile; that is, when the computer is switched off, the contents of RAM vanish. The operating system is a set of system programs. The operating system provides programs for file management and controlling storage devices such as hard disks and floppy disks, as shown in Figure.

Fig: Communication between program, file, and output device
As shown in Figure, the data read from the keyboard are stored in variables. Variables are created in RAM (type of primary memory). On applying the disk, I/O operations selected or all variables created in RAM can be stored to secondary storage devices such as hard disks or floppy disks. In Figure, the floppy disk is indicated. It is also possible to read data from secondary storage devices. When data are read from such devices, they are placed in the RAM and then, console I/O operations are used to transfer them to the screen. RAM is used to hold data temporarily. The variables are used to store data during program execution, and the variables are created in RAM. Hence, the secondary storage device RAM plays an important role.

The file is an accumulation of the data stored on the disk created by the user. The programmer assigns a file name. The file names are unique and are used to identify the file. No two files can have a similar name in the same directory. There are various types of files such as text files, program files, data files, and executable file. Data files contain a combination of numbers, alphabets, symbols, and so on called data.

Data communication can be performed between programs and output devices or between files and programs. File streams are used to carry the communication among the above-mentioned devices. The stream is nothing but a flow of data in bytes in sequence. If data were received from input devices in sequence, then it is called a source stream, and if the data were passed to output devices, then it is called a destination stream. Figure shows the input and output streams. The input stream brings data to the program, and the output stream collects data from the program. In this way, the input stream extracts data from the file and transfers it to the program; whereas the output stream stores the data in the file provided by the program.

Fig: Input and output streams

Test Your Skills Now!
Take a Quiz now
Reviewer Name