`import` — C++ Keyword
`import` — C++ Keyword
The import keyword in C++20: imports a named module or header unit into the current translation unit.
`import` — C++ Keyword
The import keyword in C++20: imports a named module or header unit into the current translation unit.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
importMakes the exported names of a named module or a header unit available in the current translation unit. Introduced in C++20.
import module-name;
import <header>; // import standard library header as header unit
import "header.h"; // import local header as header unit
// --- greeting.cppm ---
export module greeting;
export void say_hello(const char* name);
// --- greeting.cpp ---
module greeting;
#include <print>
void say_hello(const char* name) {
std::println("Hello, {}!", name);
}
// --- main.cpp ---
import greeting;
int main() {
say_hello("World"); // Hello, World!
}
import std; (C++23) imports the entire C++ standard library as a module.import <vector>; imports a header as a header unit (requires precompilation of the header).#include, imported names are not re-exported to importers of the current module.int main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}