Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

#include — header inclusion

The #include directive makes a header or source file's contents available during preprocessing. The <header> and "file" forms use different searches; the implementation defines the specific search rules.

Version: C++23; repository compiler flag, production runtime not attested

Syntax

#include <header>
#include "file"
#include MACRO

#include is a preprocessing directive, not a call executed at runtime. Ordinarily, it is replaced by the contents of the specified header or file, which is also preprocessed. A newline ends the directive, not a semicolon.

The #include <header> form searches for a header, while #include "file" first searches for a source file, falling back to header search if unsuccessful or unsupported. Search locations are implementation-defined: quotation marks do not guarantee the current directory. Conventionally, use <...> for implementation headers and "..." for your own files.

The #include MACRO form expands macros. After expansion, the directive must have one of the two valid forms: #include <header> or #include "file". The quoted form can name a source file. If the specified header or file cannot be found under the search rules, the program is ill-formed. An implementation may replace inclusion of an importable header with a header-unit import.

Include a standard library header outside declarations and definitions, before using the facilities it provides. In the example, <iostream> makes std::cout available. The supplied sources are a living standard draft, not a frozen C++23 text.

Examples

#include <iostream>

int main() {
    std::cout << "Hello\n";
}

Result

Hello

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources