5

I'm working in Visual studio 2010. I Added a directory to Project Properties -> Linker -> General -> Additional Directories

The project compiles if I use

 "file.h"

but not if i use

 <file>
Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
nulltorpedo
  • 1,195
  • 2
  • 12
  • 21

3 Answers3

11

You are probably assuming that < > implicitly adds .h to the end of the file name. This is not true. Whether you use < > or " " has no significance on the name of the file. It basically tells the implementation in which order it should traverse include directories to find the header file.

To quote the standard:

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

Community
  • 1
  • 1
Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • 1
    "…tells the _preprocessor_" :-P – sidyll Nov 16 '11 at 23:19
  • 1
    @sidyll The technically correct term would be "the *implementation*". The standard does not specify whether or not preprocessing should be done by a separate program. – Mehrdad Afshari Nov 16 '11 at 23:22
  • 2
    To complete this answer, it would be nice to also explain that and might not be the same file AND that standard library files provided by the compiler do not have extension. That way you can make the difference with other files that need to be in the include paths. – Klaim Nov 16 '11 at 23:44
  • @Klaim Indeed. To further clarify, C standard library headers all have `.h` extension whereas C++ ones don't have any extension. – Mehrdad Afshari Nov 16 '11 at 23:48
  • 1
    @Klaim: we even have an example: `` is the C++ string-related stuff (`basic_string` & co.), while `` is the legacy header for C string-handling functions. – Matteo Italia Nov 16 '11 at 23:54
5

"" is for local files and <> are from files in the C library.

Dieter De Mesmaeker
  • 2,156
  • 2
  • 14
  • 14
1

An include works only if there is exists such a file. In your case it might be cause there is a file file.h but note simply file.

You probably think it should work everywhere as you might have seen it with iostream.h and iostream. This is because they are two different files which mean two different things.

Community
  • 1
  • 1
parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85