- #1
- 16,336
- 258
D H said:In every implementation I have come across, the key difference between #include "file_spec" and #include <file_spec> is that the former searches the directory containing the current file being processed while the latter does not. The Gnu compilers provide the -iquote option to define a quote search path that is distinct from the bracket search path, but I've never seen anyone use that option. Gnu also provides the now deprecated -I- option to split the search path into quoted and bracketed parts. I've never seen anyone use that, either. (I have however seen programming standards that forbid the use of this option.)
It's a pity that the various coding standards that I have seen are inconsistent as to when to use #include "file_spec" or #include <file_spec>.
The "High Integrity C++ Coding Standard" says:
High Integrity CPP Rule 14.9: Use <> brackets for system and standard library headers. Use "" quotes for all other headers. (QACPP 1011, 1012)
Justification: It is important to distinguish the two forms of #include directive not only for documentation purposes but also for portability. Different compilers may have different search methods and may not find the correct header file if the wrong form of #include is used.
Reference: Industrial Strength C++ 15.4;