【问题标题】:I wrote a basic code and its not working in Visual Studio Code我写了一个基本代码,它在 Visual Studio Code 中不起作用
【发布时间】:2021-06-01 15:47:51
【问题描述】:
#include<iostream>
using namespace std;
int main() {
    cout<<"Hello World";
    return 0;
}

PS D:\vs> cd "d:\vs" ; if ($?) { g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile } ; if ($?) { .\tempCodeRunnerFile } c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../ lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): 未定义对“WinMain@16”的引用 collect2.exe:错误:ld 返回 1 个退出状态

我写了这段代码。我正在使用 Visual Studio 代码。我已经安装了 C/C++ 和 Code Runner 等扩展。我已经正确安装了mingw。 我还添加了 mingw/bin 的环境变量。它不断显示此错误消息,我已经尝试了一切。

【问题讨论】:

标签: c++ visual-studio-code


【解决方案1】:

问题已回答here,基本上这个错误是在编译器无法识别主函数时出现的,但您似乎确实有一个,所以在编译之前尝试手动保存。

【讨论】:

  • 创建了一个新的 .exe 文件,但现在我的防病毒软件自动删除了该 .exe 文件并显示发现木马......当我停止我的防病毒软件时,它正在工作...... ....但是那个木马可能会影响我的电脑
【解决方案2】:

当您在运行之前不保存或者您只是选择一段代码并尝试运行它时,就会发生这种情况。这就是问题所在。

【讨论】:

    【解决方案3】:
    #include<iostream>
    using namespace std;
    int main(){
        cout <<"hello world";
        return 0;
    // you have to press ctrl+shift+b then search box open choose g++.exe to build task then type g++ .\4.cpp then run .\4.exe ur code is run . otherwise u r not install prooperly compilee.
    }
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2021-06-18
    相关资源
    最近更新 更多