HiveBrain v1.2.0
Get Started
← Back to all entries
gotchacppCritical

Difference between angle bracket < > and double quotes " " while including header files in C++?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
doublequoteswhileandbetweenheaderangledifferencefilesincluding

Problem

Possible Duplicate:

What is the difference between #include and #include “filename”?

What is the difference between angle bracket ` and double quotes " " while including header files in C++?

I mean which files are supposed to be included using eg:
#include and which files are to be included using eg: #include "MyFile.h"`???

Solution

It's compiler dependent. That said, in general using " prioritizes headers in the current working directory over system headers. <> usually is used for system headers. From to the specification (Section 6.10.2):


A preprocessing directive of the form

# include  new-line




searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the ` delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.


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  new-line




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

So on most compilers, using the
"" first checks your local directory, and if it doesn't find a match then moves on to check the system paths. Using <>` starts the search with system headers.

Code Snippets

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

Context

Stack Overflow Q#3162030, score: 361

Revisions (0)

No revisions yet.