Where Does Visual Studio Look For C++ Header Files

Where does Visual Studio look for C++ header files?

Visual Studio looks for headers in this order:

  • In the current source directory.
  • In the Additional Include Directories in the project properties (Project -> [project name] Properties, under C/C++ | General).
  • In the Visual Studio C++ Include directories under ToolsOptionsProjects and SolutionsVC++ Directories.
  • In new versions of Visual Studio (2015+) the above option is deprecated and a list of default include directories is available at Project PropertiesConfigurationVC++ Directories

In your case, add the directory that the header is to the project properties (Project PropertiesConfigurationC/C++GeneralAdditional Include Directories).

How to tell VSCode where to find header and source files

Open the Command Palette (F1 or Ctrl+Shift+P), look for "C/C++: Edit configurations (UI)", and add the desired folders under "Include path". This will allow Visual Studio Code's IntelliSense to know where your header files are located.

For an optimized experience, don't forget to also set up the path to the compiler, the IntelliSense mode appropriate for that compiler, and the C/C++ standards you are using.

PS: For more on how to use VS Code for C and C++ programming, you may be interested in these lecture notes I wrote for a graduate course I'm teaching.

In Visual Studio C++, How to quickly find necessary header files?

I tested this feature in vs2019 community 16.3.6 and it works. When you hover the mouse at the location of an error, you can see an error light bulb. And click the drop-down arrow next to the error bulb to add missing #include.

Sample Image

You can also press Alt+Enter.

How do I include a header file located in a specific folder? (C++)

Try this

#include "files/myheader.h"

It will work if the header is in a files folder in the same directory as the current source.


If you're trying to include a 3rd party library and not your own header, I'd suggest you to save the library headers in a particular path (say C:\Library\headers). (If there are static libraries put them in some other path like C:\Library\lib).

  1. In your Visual Studio C++ Project, go to View > Other Windows > Property Manager.

Property Manager Window


  1. Double Click on the Project Name. You will see a dialog box like this:

Property Page Editor

Make sure All Configurations is chosen in the dropdown, if you want the change to be applied to both the Debug and the Release Configurations. Else just choose the Configuration you want the properties to be applied to.


  1. Go to VC++ Directories on the left and choose Include Directories in the right, and enter the path(s) in the textbox separated by a ;.

You can also use the drop down and use the Dialog box to add the paths if you'd prefer to browse to each path separately

Edit1
Edit2


  1. Add the library path the same way to Library Directories
  2. Save the changes using the Save button on the Property Manager Pane's toolbox.

You will then be able to access the header file contained in the directory you added by something like:

#include <myheader.h>

This approach will help, because it won't matter where the headers saved. The header path is not hard-coded.


Visual Studio can't 'see' my included header files

If you choose Project and then All Files in the menu, all files should be displayed in the Solution Explorer that are physically in your project map, but not (yet) included in your project. If you right click on the file you want to add in the Solution Explorer, you can include it.



Related Topics



Leave a reply



Submit