Summary
In this post, I will introduce the different between #include "file"
and #include <file>
in C++.
Conclusion
#include <file>
This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option.
#include "file"
This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>
. You can prepend directories to the list of quote directories with the -iquote option.
Options
-I dir
-iquote dir
Add the directory dir to the list of directories to be searched for header files during preprocessing.
Directories specified with -iquote apply only to the quote form of the directive, #include "file"
. Directories specified with -I apply to lookup for both the #include "file" and #include <file>
directives.
You can specify any number or combination of these options on the command line to search for header files in several directories. The lookup order is as follows:
- For the quote form of the include directive, the directory of the current file is searched first.
- For the quote form of the include directive, the directories specified by -iquote options are searched in left-to-right order, as they appear on the command line.
- Directories specified with -I options are scanned in left-to-right order.
- Directories specified with -isystem options are scanned in left-to-right order.
- Standard system directories are scanned.
- Directories specified with -idirafter options are scanned in left-to-right order.