C++ offers its users a variety of functions, one of which is included in header files. In C++, all the header files may or may not end with the “.h” extension unlike in C, Where all the header files must necessarily end with the “.h” extension. Header files in C++ are basically used to declare an interface of a module or any library.
A header file contains the following:
It offers the above features by importing them into the program with the help of a preprocessor directive “#include” . These preprocessor directives are used to instruct the compiler that these files need to be processed before compilation. In C++ program has the header file which stands for input and output stream used to take input with the help of “cin” and “cout” respectively.
#include // for files already available in system/default directory or #include "filename.h" // for files in same directory as source file
We can include header files in our program by using one of the above two syntaxes whether it is the pre-defined or user-defined header file. The “#include” preprocessor is responsible for directing the compiler that the header file needs to be processed before compilation and includes all the necessary data types and function definitions.
The below example illustrates the inclusion of header files in a C++ program.