Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

include "file.h" vs <file> what is the difference?

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>
like image 776
nulltorpedo Avatar asked Nov 16 '11 23:11

nulltorpedo


People also ask

What is the difference between #include file H and #include file H?

#include" " is used for header files in current directory, The compiler while resolving symbols searches the current directory for the header file. the other case of is used for standard directory searches of header files i.e as usually directed by makefiles.

What is the difference between include file and #include file?

The difference between the two types is in the location where the preprocessor searches for the file to be included in the code. #include<> is for pre-defined header files. If the header file is predefined then simply write the header file name in angular brackets.

Should I include the H file or cpp file?

While it is certainly possible to do as you did, the standard practice is to put shared declarations into header files (. h), and definitions of functions and variables - implementation - into source files (. cpp).

What does file H mean?

What is an H file? A file saved with h file extension is a header file used in C/C++ files to include the declaration of variables, constants, and functions. These are referred by the C++ implementation files that contain the actual implementation of these functions.


2 Answers

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

like image 119
mmx Avatar answered Nov 07 '22 16:11

mmx


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

like image 42
Dieter De Mesmaeker Avatar answered Nov 07 '22 16:11

Dieter De Mesmaeker