Fish say, they have their stream and pond; but is there anything beyond?
RUPERT BROOKE, “Heaven” (1913)
As a leaf is carried by a stream, whether the stream ends in a lake or in the sea, so too is the output of your program carried by a stream not knowing if the stream goes to the screen or to a file.
I/O refers to program input and output. Input can be taken from the keyboard or from a file. Similarly, output can be sent to the screen or to a file. This chapter explains how you can write your programs to take input from a file and send output to another file.
Input is delivered to your program via a C++ construct known as a stream, and output from your program is delivered to the output device via a stream. Streams are our first examples of objects. An object is a special kind of variable that has its own special-purpose functions that are, in a sense, attached to the variable. The ability to handle objects is one of the language features that sets C++ apart from earlier programming languages. In this chapter we tell you what streams are and explain how to use them for program I/O. In the process of explaining streams, we will introduce you to the basic ideas about what objects are and about how objects are used in a program.
This chapter uses the material from Chapters 2 through 5.