Thread: #include confusion

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    #include confusion

    What is the difference between:

    #include "xyz.h"

    and

    #include <xyz.h>


    And how do you call them?


    Thanks.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    #include "..."

    Includes a file in the current directory (or looks there first then moves to the compilers' include directory).

    #include <...>

    Includes a file from wherever the compiler is set-up to include headers from. If it can't be found it's searched for in the current directory.

    I'm not sure if the searching elsewhere is compiler specific, but a quick browse of the C standard would clear that up if you're interested.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The former is generally used for user defined header files while the latter is usually used for standard headers, or those of libraries that you install into the compiler's include directory.

    The compiler usually searches for the former ("xyz.h") with respect to the current directory and whatever other include directories are specified (or if it still cannot find a matching file, it will then search as if it was the latter), but will look for the latter (<xyz.h>) in its own include directory.

    Of course, the details of how the search for a matching header is conducted is implementation dependent (except for that fallback from "xyz.h" to <xyz.h>, which is guaranteed), but that is the general idea.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    75
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use this part of dirent.h
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 01-31-2009, 08:51 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 06:23 AM
  4. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  5. Socket programming
    By kahad in forum C Programming
    Replies: 3
    Last Post: 12-14-2006, 04:37 PM