n the C and C++ programming languages, what is the difference between using angle brackets and using quotes in an include statement, as follows?


#include "path-spec" //Quotes

#include <path-spec> //Angular brackets

As you know that # sign is used for processor directive, which tells the compiler to do preprocessing before going to the actual program. You are quite familiar with using angular brackets to add a header file in your program. The only thing which is confusing is why we use quotes for the same purpose. Both angular brackets and quotes do the same job but way of doing is different.

In above example “path-spec” is the name of file that has to be included in your program i.e. <stdio.h>, “iostream” etc.

So let starts with the angular brackets <> how they include files in your program. When you use angular brackets with #include it looks for the file in directories that are predefined by the IDE/Compiler. Every compiler made a list of predefined directories using -I or /I option. So whenever you use angular brackets you can say your trying to access built-in (standard) library header files.

In case of quotes “” it first looks for the file in directory where the your program is located or you can say in directory your working. If it doesn’t find that file there then it’ll work as same of angular bracket <>. So using quotes you can say your adding user defined header files.

Below are some points in tabular form that’ll explain you better.

Syntax FormAction
Quoted formThe preprocessor searches for include files in this order:

  1. In the same directory as the file that contains the #include statement.
  2. In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.
  3. Along the path that’s specified by each /I compiler option.
  4. Along the paths that are specified by the INCLUDE environment variable.
Angle-bracket formThe preprocessor searches for include files in this order:

  1. Along the path that’s specified by each /I compiler option.
  2. When compiling occurs on the command line, along the paths that are specified by the INCLUDE environment variable.

Table Source: https://msdn.microsoft.com/en-us/library/36k2cdd4.aspx