954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

#include "" vs. #include <>

Ok, so I have a stupid question to ask, and I aks all of you not to ridicule one who is merely looking for knowledge.

What is the difference between using

#include "whatever"


versus using

#include <whatever>


? I've always used the brackets versus the quotes, and have tried looking into google, but when searching for something like "#include """ there are a lot of results that come up with a lot of other forums and such where there's a line in their code that reads "#include"... so I don't know where to look for this stuff...


Thanks. :)

Derek Elensar
Light Poster
39 posts since Feb 2011
Reputation Points: 44
Solved Threads: 2
 

The difference depends on the compiler you are using. Some compilers treat them the same, while others don't. With vc++ the <> tells the compiler to only look in its standard include directories (there are options to add to the list of directories), while the "" tells the compiler to first look in the program's source directory, it the header file is not there then the compiler will look in its standard directories just as if you had used <>.

I think google made a recent change to its search algorithms because some things seem to be more difficult to find than previously.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Using quotes ("blah") instead of angle-brackets (<blah>) changes the compiler's behavior while it searches for the #included file.

Using quotes makes the compiler look in the source file's local directory, then the default include directory. Using angle-brackets makes the compiler go directly to the default include directory and ignore the local directory when it searches.

Basically, if you're writing a custom header, you should use quotes (i.e. "myClass.h") and use brackets for any standard headers (i.e. , , etc.).

See this.

EDIT:
Oops, AD beat me to it.

Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 

The standard says that angle brackets cause the compiler to look in an implementation-defined location and double quotes cause the compiler to look in an implementation-defined location. I can see how there might be confusion. ;)

Traditionally the angle brackets searched the compiler's include locations followed by local directories, while double quotes did the opposite. Best practice has been to use angle brackets for compiler provided headers and double quotes for everything else.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Ok, thanks guys. That makes sense to me :D

Derek Elensar
Light Poster
39 posts since Feb 2011
Reputation Points: 44
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You