0

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

When I written my programs, I include libraries like #include <iostream> . but also #include "iostream" is correct and the code would compiled without any error or problem.

So, I'm wondering what's the difference between < > and " " ?

Community
  • 1
  • 1
Hamed
  • 2,084
  • 6
  • 22
  • 42

4 Answers4

1

The double-quotes include are used to tell the compiler to look for the included header file in the local directory first before searching for it in the include directories. You can see this difference when you're trying to include on of your local header file of your code. If you used '<>' to include your local header file, the compiler will fail unless your local directory is the 'include' directory paths.

Vite Falcon
  • 6,575
  • 3
  • 30
  • 48
1

When you use < >, the compiler only looks in the system-designated directory/directories (e.g., whatever you've set in the include environment variable) for the header.

When you use " ", the compiler looks in the local directory first, and if that fails, re-searches just like you'd used < >. Technically, (i.e., according to the standard) that doesn't have to be the "local" directory, but that's how it works in essentially every compiler of which I'm aware).

In case you care, the official wording from the standard is actually kind of vague (§16.2/2-3):

A preprocessing directive of the form

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

searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > 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 <h-char-sequence> new-line

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

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

<> only looks in the compiler provided header files while "" looks in the project directory first and only looks in the compiler provided header files if nothing is there.

Add an file called iostream next to your source file. Now include with "" and watch it fail (since it will get the empty file) or use <> and watch it succeed (since it will ignore the local file).

R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187
0

"XXX" - Its in your one directory. - Its in the SDK of Microsoft, or any SDK (you can add in the

Ido Hadar
  • 25
  • 6