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.
|Quoted form||The preprocessor searches for include files in this order:|
|Angle-bracket form||The preprocessor searches for include files in this order:|
Table Source: https://msdn.microsoft.com/en-us/library/36k2cdd4.aspx