Visual Studio — does not create exe file

六眼飞鱼酱① 提交于 2020-07-21 04:24:43

问题


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!


回答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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/41755237/visual-studio-does-not-create-exe-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!