stream of Consciousness

A stream is a facility that allows us to use various input and output devices more or less uniformly. There are a number of variants of this data type, which are related by inheritance so that we can substitute a more highly specialized variant for a more basic one. So far we've encountered istream, ostream, ifstream, ofstream, and of course most recently strstream. The best place to start a further investigation of this family of classes is with one of the simplest types, an ostream. We've used a predefined object of this type, namely cout, quite a few times already. To see a little bit more about how this works, take a look at the program in Figure 9.15.

Figure 9.15. A simple stream example (code\stream1.cc)

When ...

Get Learning to Program in C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.