#include
The #include
directive in C++ is used to include header files in our program.
When we include a header file, the contents of that header file are copied and pasted into our program at the location where the #include
directive is written. This allows us to use the declarations and definitions present in the included header file.
The syntax for using #include
directive is as follows:
#include <header_file_name>
Here, header_file_name
refers to the name of the header file we want to include in our program. We enclose the header file name within angle brackets < >
if it is a system header file, or within double quotes " "
if it is a user-defined header file.
For example, let's say we want to include the header file iostream
in our program. We can do so by writing:
#include <iostream>
This allows us to use the declarations and definitions present in the iostream
header file, such as cout
and cin
.
Including the necessary header files is an important step in C++ programming as it provides access to various predefined functions and classes that we can use in our program.