Home > OS >  My Visual Studio can't find files and so can't do basic operations. What's wrong with
My Visual Studio can't find files and so can't do basic operations. What's wrong with

Time:09-29

Using C , if I launch an 'empty project', create a new C file, and try to run it, I just get this error message:

Unable to run program 'C:\Users\User\source\repos\Project2\Debug\Project2.exe' The system cannot find the file specified

I go to the file it's referencing and the file IS there -- what??

Using a 'Console App' project is different: it will actually compile and run the code.

Similarly, I can't join new header files to the main file, not even in a 'Console App' project: if I write the code for doing #include "Header.h", I get a red line underneath #include, and if I hover over that it says:

cannot open source file "Header.h"

I'm new to coding, and don't know why I'm having such a seemingly absurd problem here. Help!

CodePudding user response:

From the result you described, I suspect you used File -> New file to add that cpp file, right? This does NOT add that file to a project.

Instead, you should right-click the Project file in the Solution explorer, select Add new item (or Project -> Add new item menu), and choose the C file type.

This works!

CodePudding user response:

You should create a new project and then create a c file. While adding a file, make sure to select c console application and do not check empty project if you are new.

  • Related