In the real world, computer applications need to store large amounts of
data for extended periods of time. Imagine the amount of data stored and
To accomplish the task of storing large amounts of data,
files are used.
There are two types of data files:
Files: These files must be
accessed in the same order in which they were written. This process is
analogous to audio cassette tapes where you must fast forward or rewind
through the songs sequentially to get to a specific song.
In order to access data from a sequential file, you must start at the
beginning of the file and search through the entire file for the data that you
Random Access Files: These
files are analogous to audio compact disks where you can easily access any
song, regardless of the order in which the songs were recorded. Random
access files allow instant access to any data in the file.
Unfortunately, random access files often occupy more disk space than
sequential access files.
Remember that a C++ program
views input (or output) as a stream
of bytes. On input, a program extracts
(>>) bytes from an input
stream. On output, a program
inserts (<<) bytes into the output
stream. The stream acts as a mediator between the program and the
stream's source or destination.
In this same manner, input
and output data is handled by use of a
is a block of memory used as an
intermediate, temporary storage area for the transfer of information between a
program and a device (e.g. file).