0

I am trying to add some .h and .c files to a C++ project. However, the library calls header files by using <> instead of "". And the Microsoft Visual Studio 2015 tells me it can't open the header file. When switched to "" it can open it. I don't want to go through 100 files and change <> to "".

Is there any solution to this problem?

emirgo
  • 15
  • 5
  • The compiler might behave different than the other you might know. Add a path to the folder with the file: https://learn.microsoft.com/en-us/cpp/build/reference/i-additional-include-directories?view=msvc-160 – harper Feb 24 '21 at 12:51
  • 1
    It means your `INCLUDE` paths are wrong. Also, why are you using VC2015? – Dai Feb 24 '21 at 12:51
  • 1
    @Dai In a way, however these files aren't system level files. They are within the same path. So do I really have to churn through a bunch of files manually? – emirgo Feb 24 '21 at 12:52
  • @Dai Yes, the question isn't new. But the cited answer might miss the visual-studio environment. – harper Feb 24 '21 at 12:52
  • If they are in your project you are supposed to use quotes. If they are system you are supposed to use <> however I believe the searching method is up to the implementation – drescherjm Feb 24 '21 at 12:56
  • Project > Properties > VC++ Directories, edit Include Directories – Hans Passant Feb 24 '21 at 12:57
  • You could add your project folders to the Include paths. – drescherjm Feb 24 '21 at 12:59

2 Answers2

0

When you use <>, the compiler searches for the header file only in the standard libraries.

And , when you use "", compiler searches for the header file in your project directory.

Assuming file.h is a header file created by you and present in your project directory, compiler will be able to find the header file only when you use #include "file.h"

0

When using include to quote header files, the difference between " " and < >:

  1. " ": To quote the header file of a non-standard library, the compiler first searches in the directory where the program source file is located. If it is not found, it goes to the system default directory to search, usually used to quote user-defined header files.

  2. < >: search only in the system default directory or the path in angle brackets.It is usually used to reference the header files that come with the standard library.

In summary, the header files that come with the standard library can use " " or < >, but we are used to using < >, and user-defined header files can only use " ".

However, you could add the directory path where file.h is located in Properties->VC++ Directories->Include Directories. enter image description here

In general, using " " for self-written, and < > for header files of the third-party libraries or system libraries.

Barrnet Chou
  • 1,738
  • 1
  • 4
  • 7