#include
Go Up to Preprocessor Directives Index
Syntax
#include <header_name> #include "header_name" #include <macro_definition>
For information about #include syntax with Clang-enhanced C++ compilers, see Clang-enhanced C++ Compilers, #include Paths and Lookup.
Description
The #include directive pulls in other named files (known as include files, header files or headers) into the source code. The syntax has three versions:
- The first and second versions imply that no macro expansion will be attempted; in other words,
header_name
is never scanned for macro identifiers.header_name
must be a valid file name with an extension (traditionally .h for header files) and optional path name and path delimiters. - The third version assumes that neither
<
nor"
appears as the first non-whitespace character following #include; further, it assumes a macro definition exists that will expand the macro identifier into a valid delimited header name with either of the<header_name>
or"header_name"
formats.
The preprocessor removes the #include line and conceptually replaces it with the entire text of the include file at that point in the source code. The source code itself is not changed, but the compiler "sees" the enlarged text. The placement of the #include can therefore influence the scope and duration of any identifiers in the included file.
If you place an explicit path in the header_name
, only that directory will be searched.
The difference between the <header_name>
and "header_name"
formats lies in the searching algorithm employed in trying to locate the include file:
Syntax Form | Searching Algorithm |
---|---|
Quoted form |
The
|
Angle-bracket form |
The |