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

By : quest49
Source: Stackoverflow.com
Question!

In the C and C++ programming languages, what is the difference between using angle brackets and using quotes in an include statement, as follows?

  1. #include <filename>
  2. #include "filename"
By : quest49


Answers

It does:

"mypath/myfile" is short for ./mypath/myfile

with . being either the directory of the file where the #include is contained in, and/or the current working directory of the compiler, and/or the default_include_paths

and

<mypath/myfile> is short for <defaultincludepaths>/mypath/myfile

If ./ is in <default_include_paths>, then it doesn't make a difference.

If mypath/myfile is in another include directory, the behavior is undefined.



#include <filename>

The preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE.

This method is normally used to include standard library header files.

#include "filename"

The preprocessor searches in the same directory as the file containing the directive.

This method is normally used to include programmer-defined header files.



#include <filename>

is used when you want to use the header file of the C/C++ system or compiler libraries. These libraries can be stdio.h, string.h, math.h, etc.

#include "path-to-file/filename"

is used when you want to use your own custom header file which is in your project folder or somewhere else.

For more information about preprocessors and header. Read C - Preprocessors.



This video can help you solving your question :)
By: admin