them and run them on a Sun Workstation, or you can take code created using a Windows
C++ compiler and recompile and run it on Linux. The compiler manufacturer supplies
the right library, and everything works. At least that’s the theory.
594 Day 17
A library is a collection of object (.objor .o) files that can be linked to your
program to provide additional functionality. This is the most basic form of
code reuse and has been around since ancient programmers chiseled 1s and
0s into the walls of caves.
NOTE
Today, streams are generally less important for C++ programming—except, perhaps, for
flat file input. C++ programs have evolved to use operating system or compiler vendor-
provided graphical user interface (GUI) libraries for working with the screen, files, and
the user. This includes Windows libraries, X Windows libraries, and Borland’s Kylix
abstraction of both the Windows and X Windows user interfaces. Because these libraries
are specialized to the operating system and are not part of the C++ standard, they are not
discussed in this book.
Because streams are a part of the C++ standard, they are discussed today. In addition, it
is good to understand streams in order to understand the inner workings of input and out-
put. You should, however, quickly move to learning your operating system or vendor-
supplied GUI library as well.
Encapsulation of Data Flow ..........................................................................
Text input and output can be accomplished using the iostreamclasses. The iostream
classes view the flow of data as being a streamof data, one byte following another. If the
destination of the stream is a file or the console screen, the source of the data that will be
flowing is usually some part of your program. If the stream is reversed, the data can
come from the keyboard or a disk file and can be “poured” into your data variables.
One principal goal of streams is to encapsulate the problems of getting the data to and
from the disk or the console screen. After a stream is created, your program works with
the stream and the stream takes care of the details. Figure 17.1 illustrates this fundamen-
tal idea.
Understanding Buffering ................................................................................
Writing to the disk (and to a lesser extent the console screen) is very “expensive.” It
takes a long time (relatively speaking) to write data to the disk or to read data from the
disk, and execution of the program can be blocked by disk writes and reads. To solve this