#include (C++)

#include is a preprocessor directive that pastes the contents of a header file into your source code before compilation. It is how you gain access to standard library features and other code.

C++

Use angle brackets (#include <iostream>) for standard or system headers, and quotes (#include "myfile.h") for your own project files.

The #include line runs before the compiler proper, during a phase called preprocessing. Without including <iostream>, for example, names like std::cout would be unknown.

Syntax

#include <header>
#include "file.h"

Examples

C++

#include <iostream>
#include <vector>

int main() {
    std::vector<int> nums = {1, 2, 3};
    std::cout << nums.size() << std::endl;
    return 0;
}

Output:

3

Learn it in a lesson

See also

Back to the Dictionary