3

Will

#include "filename"

always search for a file in standard include directory if not found in the current directory or for some compilers may not?

Is it possible to turn off searching for the file in standard include directories using this directive for example for gcc?

michalt38
  • 1,193
  • 8
  • 17
  • It literally takes the full path, if there is no full path and just a filename it is the same as doing #include "./filename" which will search the current directory for that file. If it is somewhere else other than the file you are including it in, then you can do something like #include "../../someOtherDirectory/filename" – Omid CompSCI Mar 27 '20 at 23:04
  • Relevant https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename if you are interested in including from the standard library it is expected/canonical to include it like `#include ` for example – Cory Kramer Mar 27 '20 at 23:05

1 Answers1

5

§[cpp.incluce]/2:

A preprocessing directive of the form

# include " q-char-sequence " new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

# include < h-char-sequence > new-line

with the identical contained sequence (including > characters, if any) from the original directive.

...so yes, if it doesn't find it otherwise, it always re-searches in the standard include directories.

Community
  • 1
  • 1
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111