10

Possible Duplicate:
what is the difference between #include <filename> and #include “filename”

I would like to know what's the difference between

#include "stdio.h"

and

#include <stdio.h>
Community
  • 1
  • 1
amin
  • 805
  • 2
  • 8
  • 8
  • Must be a duplicate, surely ? – Paul R Mar 04 '11 at 08:04
  • @Paul R: You could have found that out in about 5 seconds with the search box. – JeremyP Mar 04 '11 at 08:17
  • @JeremyP: evidently my Google Fu is weak this morning, as I had actually tried and failed to find any of what I am sure must be numerous duplicates. But many congratulations on finding one yourself. – Paul R Mar 04 '11 at 08:20
  • @Paul R: I used the search box on this site, not Google. I don't know if that makes a difference. – JeremyP Mar 04 '11 at 08:23
  • @JeremyP: I never seem to have much luck with the SO search box, I normally just Google for ` site:stackoverflow.com` and that seems to be more effective. But evidently not in this case (probably because Google doesn't like `<>` and `""` as search terms). – Paul R Mar 04 '11 at 08:56

3 Answers3

17

Use <whatever> for system headers, and "whatever" for your own headers.

The difference is that when it's enclosed in quotes, the compiler will look in the local directory, but with <>, it won't. If you want to get technical, the C standard doesn't guarantee that, but it's how essentially all compilers work.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
9

"" searches in current file's path. <> searches in global include paths.

Edit: You asked for absolute path and relative path.

Assume you have a file structure as follows:

folderX
 -fileX.a
 -fileX.b
 -folderX.Y
  -fileX.Y.a
  -fileX.Y.b
 -folderX.Z
  -fileX.Z.a

Then, the absolute path of fileX.Z.a would be folderX/folderX.Z/fileX.Z.a, assuming that folderX is the topmost directory available. The relative path of fileX.Z.a relative to e.g. fileX.a is just the part folderX.Z/fileX.Z.a, i.e. you start the path in the directory where fileX.a lies.

Benoit
  • 76,634
  • 23
  • 210
  • 236
phimuemue
  • 34,669
  • 9
  • 84
  • 115
5
#include <file>

This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the `-I' option.

#include "file"

This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the same directories used for .

The argument of #include, whether delimited with quote marks or angle brackets, behaves like a string constant in that comments are not recognized, and macro names are not expanded. Thus, #include specifies inclusion of a system header file named `x/*y'.

However, if backslashes occur within filename, they are considered ordinary text characters, not escape characters. None of the character escape sequences appropriate to string constants in C are processed.

Reference:

anijhaw
  • 8,954
  • 7
  • 35
  • 36