Visual Studio -- 不创建 exe 文件 [英] Visual Studio -- does not create exe file

查看:116
本文介绍了Visual Studio -- 不创建 exe 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2015 for C++ 并创建了以下基本程序:

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;
}

当我按 CTRL-F5 运行程序时(或者当我尝试以调试模式运行它时),它会生成以下错误:

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.

(注意构建成功,但是找不到.exe文件就失败了.)经过进一步检查,我发现没有生成.exe文件.

(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.

我的防病毒软件没有删除 .exe,而且我很确定问题与 PATH 没有任何关系.该程序使用 .cpp 扩展名正确命名.

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?

我发现当我在文件"选项卡下创建一个新的 C++ 文件时,会导致上述错误,因为 .cpp 文件没有添加到项目中.但是,当您右键单击解决方案资源管理器"侧栏并在那里创建一个新文件时,会添加 .cpp 并且错误消失.不管怎样,谢谢大家的回复!

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!

推荐答案

当我通过解决方案资源管理器添加 .h 文件,然后将其重命名为 .cpp 文件并将我的主文件放在那里时,我遇到了类似的问题.我必须从项目中删除 .cpp 文件,然后在生成 exe 之前再次添加它.

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.

这篇关于Visual Studio -- 不创建 exe 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆