The Basic Stream Classes


Because C++ includes the entire C library, it supports the use of C’s I/O system. However, C++ also defines its own class-based, object-oriented I/O system, which is referred to as the iostream library. When writing C++ programs, you will usually want to use the iostream library rather than C-based I/O.

At the time of this writing there are two versions of the iostream library in widespread use: the older one that is based upon the original specifications for C++ and the modern one defined by the ANSI/ISO Standard for C++. Today, most C++ compilers support both the old-style and modern iostream libraries. However, the old-style iostream library is obsolete and should not be used for new code. New code should use the modern approach as defined by the ANSI/ISO C++ Standard. The old-style iostream library is described in this chapter for the benefit of those programmers maintaining old code, or porting old code to the modern standard. The modern approach is described in Chapter 15.

For the most part, both the old-style and modern I/O systems work the same way. If you know how to use one, you can easily use the other. However, there are several important differences between the two.

First, the old-style iostream classes were defined in the global namespace. The modern iostream library is contained in the std namespace.

Second, the modern iostream library is defined using a complex, interrelated set of template classes and functions. The old-style library uses a less complicated, nontemplatized class hierarchy. Fortunately, the names of the classes that you will use in your programs remain the same.

Third, the modern iostream library defines many new data types.

Fourth, to use the old library, you need to include .h header files, such as iostream.h. These header files define the old-style iostream classes and put them into the global namespace. By contrast, to use the modern iostream library, include the new style header <iostream> in your program.

One final point: Since the old-style iostream library is nonstandard, its precise implementation will differ between compilers, and may differ slightly from that described here.

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539 © 2008-2017.
If you may any questions please contact us: