A Simple Application and Template

Chapter 12 - An Introduction to I/O in C++

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

From STREAM.H to IOSTREAM.H
One of the most exciting enhancements to the compiler is the new C++ I/O library, referred to as the iostream library. By not including input/output facilities within the C++ language itself, but rather implementing them in C++ and providing them as a component of a C++ standard library, I/O can evolve as needed. This new iostream library replaces the earlier version of the I/O library referred to as the Release 1.2 stream library.
At its lowest level, C++ interprets a file as a sequence, or stream, of bytes. At this level, the concept of a data type is missing. One component of the I/O library is involved in the transfer of these bytes. From the user’s perspective, however, a file is composed of a series of intermixed alphanumerics, numeric values, or (possibly) class objects. A second component of the I/O library takes care of the interface between these two viewpoints. The iostream library predefines a set of operations for handling reading and writing of the built-in data types. The library also provides for user-definable extensions to handle class types.
Basic input operations are supported by the istream class and basic output via the ostream class. Bidirectional I/O is supported via the iostream class, which is derived from both istream and ostream. There are four stream objects predefined for the user:
cin
An istream class object linked to standard input
cout
An ostream class object linked to standard output
cerr
An unbuffered output ostream class object linked to standard error
clog
A buffered output ostream class object linked to standard error
Any program using the iostream library must include the header file IOSTREAM.H. Since IOSTREAM.H treats STREAM.H as an alias, programs written using STREAM.H may or may not need alterations, depending on the particular structures used.
You can also use the new I/O library to perform input and output operations on files. You can tie a file to your program by defining an instance of one of the following three class types:
fstream
Derived from iostream and links a file to your application for both input and output
ifstream
Derived from istream and links a file to your application for input only
ofstream
Derived from ostream and links a file to your application for output only

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net