Name
#include directive — Includes another source file
Synopsis
#include <header> #include "sourcefile"
The #include directive
includes the contents of a standard header or source file. The first
form searches for header and replaces the
directive with the entire contents of the header. The second form
searches for sourcefile and replaces the
directive with the entire contents of the named source file.
The basic action of #include
is to read the named file or header as though its entire contents
appeared in the source file at the position of the #include directive. Typically, common
declarations are placed in a separate file, such as decl.h, and #include "decl.h" is used in every source file that
depends on those declarations.
If a source file contains the directive #include
"filename“, and the compiler cannot find
the external file named filename, the
compiler also tries the form #include < filename
>. Most compilers implement
these two forms of #include by
searching in different folders or directories. For example, the quote
form searches in the current directory or in the directory that
contains the source file, and the angle-bracket form searches only in
“system” directories. Such details are implementation-defined, and
some compilers might introduce further distinctions between the two
forms.
It is possible, for example, for a compiler to recognize only the standard headers in the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access