In every program, there is some data which is taken as input and generate the processed data as output following the input > process > output cycle. Therefore it is essential to know how to provide data as input and how to present the output in the desired form. C++ supports a rich set of I/O functions and operations to do this. As these functions use the advanced features of C++, programmers need to know a lot about them before implementing them in any program. It is to be noted that C++ supports all of C's rich sets of I/O functions. Programmers can use any of them within a C++ program. In this chapter, you will learn about how to manage the input/output capabilities of a C++ program.
The input/output in C++
C does not have built-in input/output facilities. Instead, it left the I/O to the compiler as external library functions (such as printf and scanf) in stdio (standard input-output) library. The ANSI C standard formalized these IO functions into Standard IO package (stdio.h). Likewise, C++ continues this approach and formalizes IO in iostream and fstream libraries.
Features of I/O in C++
Streams in C++
C++ IO is based on streams, which are a sequence of bytes flowing in and out of the programs (just like water and oil flowing through a pipe). I/O systems in C++ are designed to work with a wide variety of devices including terminals, disks and tape drives. The input-output system supplies an interface to the programmer that is independent of the actual device being accessed. This interface is known as a stream. A stream is a sequence of bytes which acts either as a source from which input data can be obtained or as a destination to which output data can be sent. The source stream which provides data to the program is called the input stream and the destination stream which receives output from the program is called the output stream.
Follow the steps below to perform input and output:
No comments:
Post a Comment