The #include directive causes the compiler to read and compile another source file. It takes these general forms:

#include "filename"

#include <filename>

The source file to be read in must be enclosed between double quotes or angle brackets. For example,

#include "MyFuncs.h"

will instruct the compiler to read and compile the file MyFuncs.h.

If the filename is enclosed by angle brackets, the file is searched for in a manner defined by the creator of the compiler. Often, this means searching some special directory set aside for header files. If the filename is enclosed in quotes, the file is looked for in another implementation-defined manner. For many implementations, this means searching the current working directory. If the file is not found, the search is repeated as if the filename had been enclosed in angle brackets. You must check your compiler’s user manual for details on the differences between angle brackets and double quotes. #include statements can be nested within other included files.

In addition to files, a C/C++ program uses the #include directive to include a header. C and C++ define a set of standard headers that provide the information necessary for the various libraries. A header might refer to a file, but need not. Thus, a header is simply an abstraction that guarantees that the appropriate information is included. As a practical matter, however, C headers are nearly always files and the names of the headers are valid filenames. However, for C++, the situation is different. All C++ header names are standard identifiers that the compiler may map to a filename, or handle in another manner. Since the C++ headers are not filenames, they do not have .h extensions. For example, to include the header information for the C++ I/O system, use

#include <iostream>

Here, <iostream> is the standard header for the I/O classes.

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: