What's the difference between #include filename and #include "filename"?

8

Why we use

#include <filename>

and

#include "filename"

When to use each?

    
asked by anonymous 04.01.2017 / 13:36

1 answer

9
#include <filename>

Used for standard language libraries. In general the compiler already knows where the headers are that is part of the language. Obviously this can be configured. But how it will be done is implementation issue .

Of course nothing prevents you from putting other things together, but it is not recommended.

Then

#include <filename.h>

You should probably access /usr/include/file.h or C:\Program Files\Microsoft SDKs\Windows\v10.0\Include

In C ++ you generally do not need to use .h , at least for language-specific headers and not those that are "imported" from C, although it has names with .h to access the C headers (eg. : cstdio instead of stdio.h ).

Note that it is not necessary to have an existing filename, the written name needs to define what the header is, how it will figure out what it should include depending on the compiler, and it is common to have these names which makes a mapping to other files (eg cstring -> string.h ).

#include "filename"

Used for third-party libraries and their own code. In general it looks in the folder of what is being compiled. There are directives in the compiler to add other locations. The exact implementation is also compiler dependent.

If this search can not be done, it decays to the previous form. If you do not find anything, there will be an error.

Then

#include "file.h"

must access ./file.h .

In C ++ some people prefer to use .hpp to make it clear that it is compatible with C ++ and not C.

    
04.01.2017 / 13:36