Overview
A program is a set of instructions that perform operations on the data to generate a desired output. The data is generally provided to the program from external sources. These sources are called inputs, which are given to the program to attain the required results. On receiving the input data, the C++ code must perform necessary computations to generate the results. These results are called the outputs, which are either to be stored somewhere or rendered to the user.
It is important to note that a program can take inputs from multiple sources like keyboard, mouse, files, database, and so on. Along the same lines, a program can distribute its output to multiple destinations like computer screen (for rendering), files, database, speaker, and so on. The selection of input sources and output destinations purely depends upon the business requirements on the basis of which the code is designed.
Given a variety of inputs and outputs possible in today's world, it is important that the programming language makes it easy for the programmer to write a program that can take input from any required source(s) and distribute output to any required destination(s) using a consistent approach. What this means is that, a programming language should offer a layer of abstraction to the programmer, so as to hide the complexities of differences in each of the input/output devices. The programmer's job is to only think towards the core business logic of the program and not to worry about the communication with I/O devices. The only way to make this possible is, the programming language must provide a rich application programming interface (API) that can handle inputs and outputs in the same way for any I/O device. This API is called a stream. An input stream is the one that takes data from any of the input devices and transfers it to the program. Whereas, the output stream is the one that transfers data/results generated by the program to any of the output devices. By definition, stream is a series of bytes that are transferred between the program and the I/O device. Figure 15.1 shows the role of input and output streams to transfer data between program and external devices.
Review the options below to login to check your access.
Log in with your Cambridge Aspire website account to check access.
If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.