2

I'm working with Visual Studio 2015 for C++ and have created the following basic program:

#include <iostream>

using namespace std;

int main() {
    // for loop execution
    for (int a = 10; a < 20; a = a + 1) {
        cout << "value of a: " << a << endl;
    }

    return 0;
}

When I hit CTRL-F5 to run the program (or when I try running it with Debug mode), it generates the following error:

'"C: \Users\Verity\documents\visual studio 
2015\Projects\TestProject\Debug\TestProject.exe"' is not recognized as an 
internal or external command, operable program or batch file.

(Note that it builds successfully, but fails when it cannot find the .exe file.) Upon further inspection, I found that the .exe file is not generated.

My antivirus isn't deleting the .exe, and I'm pretty sure the problem doesn't have anything to do with the PATH. The program is named properly with a .cpp extension.

Any ideas on how to fix this?

EDIT: I found out that when I create a new C++ file under the "File" tab, it results in the above error because the .cpp file is not added to the project. However, when you right click on the "Solution Explorer" sidebar and create a new file there, the .cpp is added and the error goes away. Anyway, thanks for the responses, everyone!

quil
  • 417
  • 1
  • 6
  • 16

3 Answers3

1

I had a similar problem when I added a .h file through Solution Explorer and then I renamed it to a .cpp file and put my main in there. I had to remove the .cpp file from the project and then add it again before it would generate an exe.

0

Make sure that your project Output type is Console Application. If you right click your project -> Properties -> Application -> Output type: Console Application. Mine got changed accidentally just by using my scroll wheel and didn't notice until seeing the change in the .csproj file in source control.

Pat
  • 2,540
  • 1
  • 21
  • 28
-2

You should be able to find the .exe file under

C:\Users(username)\Documents\Visual Studio 2015\Projects(Project name)\Debug(filename).exe

Also do not run your program in debug mode. Start it without debug mode.

CraftedGaming
  • 499
  • 7
  • 21
  • Not useful. Because the build log says that it successful but still the exe is not found at the given location. ``` 1> axxx.vcxproj -> D:\src\axxx\platform\sdk\cli\driver\app1\x64\Debug\app1.exe 1> axxx.vcxproj -> D:\src\axxx\platform\sdk\cli\driver\app1\x64\Debug\app1.pdb (Full PDB) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ``` Following exe is not found: `D:\src\axxx\platform\sdk\cli\driver\app1\x64\Debug\app1.exe` – Ronak SHAH Aug 10 '20 at 05:59