In the C and C++ programming languages, what is the difference between using angle brackets and using quotes in an include
statement, as follows?
#include <filename>
#include "filename"
In the C and C++ programming languages, what is the difference between using angle brackets and using quotes in an include
statement, as follows?
#include <filename>
#include "filename"
The sequence of characters between < and > uniquely refer to a header, which isn't necessarily a file. Implementations are pretty much free to use the character sequence as they wish. (Mostly, however, just treat it as a file name and do a search in the include path, as the other posts state.)
If the
#include "file"
form is used, the implementation first looks for a file of the given name, if supported. If not (supported), or if the search fails, the implementation behaves as though the other (#include <file>
) form was used.Also, a third form exists and is used when the
#include
directive doesn't match either of the forms above. In this form, some basic preprocessing (such as macro expansion) is done on the "operands" of the#include
directive, and the result is expected to match one of the two other forms.#include <filename>
will find the corresponding file from the C++ library. it means if you have a file called hello.h in the C++ library folder,
#include <hello.h>
will load it.But,
#include "filename"
will find the file in the same directory where your source file is.
In addition,
#include "path_to_file/filename"
will find the file in the directory which you typed in
path_to_file
.Ideally, you would use <...> for standard C libraries and "..." for libraries that you write and are present in the current directory.
The order of search header files is different. <XXX.h> prefer to search the standard headers first while "XXX.h" searches the workspace's header files first.
The
#include <filename>
is used when a system file is being referred to. That is a header file that can be found at system default locations like/usr/include
or/usr/local/include
. For your own files that needs to be included in another program you have to use the#include "filename"
syntax.For
#include ""
a compiler normally searches the folder of the file which contains that include and then the other folders. For#include <>
the compiler does not search the current file's folder.