15.1 Common Background of I/O Streams
Before going into details about stream classes, I briefly discuss the generally known aspects of streams to provide a common background. This section could be skipped by readers familiar with iostream basics.
15.1.1 Stream Objects
In C++, I/O is performed by using streams. A stream is a “stream of data” in which character sequences “flow.” Following the principles of object orientation, a stream is an object with properties that are defined by a class. Output is interpreted as data flowing into a stream; input is interpreted as data flowing out of a stream. Global objects are predefined for the standard I/O channels.
15.1.2 Stream Classes
Just as there are different kinds of I/O — for example, input, output, and file access — there are different classes depending on the type of I/O. The following are the most important stream classes:
• Class istream defines input streams that can be used to read data.
• Class ostream defines output streams that can be used to write data.
Both classes are instantiations of the class templates basic_istream or basic_ostream, respectively, using char as the character type. In fact, the whole IOStream library does not depend on a specific character type. Instead, the character type used is a template argument for most of the classes in the IOStream library. This parametrization corresponds to the string classes and is used for internationalization (see also Chapter 16).