Runtime Error: Unable to start program X. The system cannot find the file specified.
This type of error is generated by the common mistake of trying to add a file to the project in an incorrect way. If you only add a file through the File menu of the Visual C++ IDE, put code in, and then try to compile, you will receive this error. The easiest solution is to add a .cpp file to the "Source Folders" folder in the project itself.
Often, it seems sensible to add a source (.cpp) file to your project by using the File menu of the Visual C++ IDE: File -> New -> File:
This will make and open a new file for you. If this is your first file in the project, you would normally put the main() function in it and write some code. The problem occurs when you then try to compile and run the program (i.e., Debug -> Start Debugging from the top menu). Instead of the IDE executing the code, you get this error:
The error message is not obvious because it suggests that it cannot find the executable file that should have been compiled from the code that you just put into the new .cpp file. However, what this error refers to is that the compiler was not able to compile any code because there were no source files in the project, and hence there is no executable file to execute.
The Solution: Adding a File through the Project or Project Menu
There are two ways to correctly add a file to a project. The easiest way to fix this problem is to open up the project, right-click on the "Source Files" folder, and select Add -> New Item.
Second, you can add a file to a project through the Project menu. Go to Project -> Add New Item:
Then choose a C++ file (.cpp), name it, and click 'Add.'
Using either method will correctly add the file directly to the project. Now, after you put code into the file, build, and run the program (i.e., Debug -> Start Debugging), your program should execute correctly.