Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The system cannot find the file specified" when running C++ program

Tags:

I installed Visual Studio 2010. I wrote a simple code which I'm sure is correct but unfortunately, when I run the code, I get the error below.

Here is my code:

#include<iostream>
using namespace std;
int main (){ 
  cout <<"Hello StackOverFlow ;)";
  return 0;
}

And here is the error:

Unable to start program 'C:\Users\Soheil\Desktop\New folder\sam\Debug\sam.exe The system cannot find the file specified

Would you help me solve the issue? Should I define the project in a specific directory? I've spent a ton of hours to solve this issue and have not had any success yet.

like image 915
Sam Avatar asked May 12 '13 20:05

Sam


People also ask

How do you solve system Cannot find the file specified?

Use SFC to fix system cannot finds the file specified error. In Command Prompt, type the following command: “sfc /scannow”. Now press Enter. After scanning and correcting errors, restart the computer and check if the “system cannot find the file specified” error is fixed.

Why does it say the system Cannot find the file specified?

As you know, most people encounter "the system cannot find the file specified" error when trying to access or back up some data. This is because the file system of the target device is corrupted or damaged, making your hard drive, USB or external hard drive inaccessible.

How do you fix the system Cannot find the file specified in Visual Studio?

I resolved this issue after deleting folder where I was trying to add the file in Visual Studio. Deleted folder from window explorer also. After doing all this, successfully able to add folder and file.


2 Answers

This is a first step for somebody that is a beginner. Same thing happened to me:

Look in the Solution Explorer box to the left. Make sure that there is actually a .cpp file there. You can do the same by looking the .cpp file where the .sln file for the project is stored. If there is not one, then you will get that error.

When adding a cpp file you want to use the Add new item icon. (top left with a gold star on it, hover over it to see the name) For some reason Ctrl+N does not actually add a .cpp file to the project.

like image 152
cdelsola Avatar answered Sep 28 '22 08:09

cdelsola


Encountered the same issue, after downloading a project, in debug mode. Searched for hours without any luck. Following resolved my problem;

Project Properties -> Linker -> Output file -> $(OutDir)$(TargetName)$(TargetExt)

It was previously pointing to a folder that MSVS wasn't running from whilst debugging mode.

EDIT: soon as I posted this I came across: unable to start "program.exe" the system cannot find the file specified vs2008 which explains the same thing.

like image 33
ReturnVoid Avatar answered Sep 28 '22 09:09

ReturnVoid