Sams Teach Yourself C++ in 21 Days

(singke) #1
Working with Streams 597

17


Streams and Buffers ............................................................................................


As you might expect, C++ takes an object-oriented view toward implementing streams
and buffers. It does this with the use of a number of classes and objects:


  • The streambufclass manages the buffer, and its member functions provide the
    capability to fill, empty, flush, and otherwise manipulate the buffer.

  • The iosclass is the base class to the input and output stream classes. The iosclass
    has a streambufobject as a member variable.

  • The istreamand ostreamclasses derive from the iosclass and specialize input
    and output stream behavior, respectively.

  • The iostreamclass is derived from both the istreamand the ostreamclasses and
    provides input and output methods for writing to the screen.

  • The fstreamclasses provide input and output from files.
    You’ll learn more about these classes throughout the rest of today’s lesson.


Standard I/O Objects............................................................................................


When a C++ program that includes the iostreamclasses starts, four objects are created
and initialized:

FIGURE17.5
Flushing the buffer.

Free download pdf