The Standard C IO Classes

As explained in Chapter 14, there are two versions of C++’s iostream library: the old style defined by early versions of C++, and the modern approach as defined by the ANSI/ISO Standard for C++ (Standard C++). The old-style library was described in the preceding section. The Standard C++ iostream library is described here.

Using the Standard C++ IostreamLibrary

There are two fundamental differences between the old-style and the Standard C++ iostream libraries. First, the old-style library was defined in the global namespace. The Standard C++ iostream library is contained in the std namespace. Second, the old-style library uses C-like .h header files. The Standard C++ library uses C++ headers (which don’t use the .h).

To use the Standard C++ iostream library, include the header <iostream> in your program. After doing that, you will usually want to bring the library into your current namespace using a statement like this:

using namespace std;

After the using statement, both the old-style and modern libraries work in much the same way.

It is not necessary to use the using statement just described. Instead, you can include an explicit namespace qualifier each time you refer to a member of the I/O classes. For example, the following explicitly refers to cout:

std::cout << "This is a test";

Of course, if you will be making extensive use of the iostream library, then including the using statement makes things less tedious.




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

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