C++ cannot open source file

112,668

Solution 1

If you're using Visual studio, right click on the project and then on Properties, Under Configuration Properties click on C\C++ and then add the directory to your header files under the Additional Include Directories section.

Solution 2

There is more information here on how to deal with this problem: Where does Visual Studio look for C++ header files?

For me, I followed xflowXen's answer and then at "Include Directories" typed in the specific pathname where my header file was located followed by a semicolon, something like: C:\Users\name\source\repos\p2-A\p2-A; then applied the changes and the issue went away.

Solution 3

For anyone still scratching their heads, you're not "supposed to" #include your own headerfiles with triangle quotes (<>), You're supposed to use "Quotation marks". It is a common mistake.

Share:
112,668

Related videos on Youtube

Author by

Jaood

Updated on February 14, 2022

Comments

  • Jaood 10 months

    In C++ with Visual studio 2017,

    I copied some header files into my project folder, then added them under the "solution explorer" in c++. Now when I write

    #include "name.h"
    

    it prints an error under include, and says "cannot open source file".

    Why, and what can I potentially do to fix it?

    I only just downloaded VS and am learning c++ for the first time.

    • Ceros
      Ceros almost 6 years
      Verify your "Additional Include Directories" in your project properties
  • drescherjm
    drescherjm almost 2 years
    Can someone explain what exactly this code has to do with the question?
  • Crann Moroney
    Crann Moroney about 1 year
    No idea what this code is doing/supposed to do. You should add some explanation

Related