用 C++ 编写的简单“Hello World”程序在 Windows 11 上不会打印任何内容

问题描述 投票:0回答:1

我刚刚学习了 C++,我正在尝试在我的 64 位 Windows 11 计算机上编写一个简单的 Hello World 程序。我使用 Visual Studio Code 编写代码,但使用命令提示符编译它。当我尝试编译它时,没有弹出错误,但是当我尝试运行它时,没有打印任何内容。

程序(main.cpp):

#include <iostream>

using namespace std;

int main() {
    cout << "Hello world!" << endl;
    return 0;
}

这是输出。输出始终存储在

main.cpp
文件旁边,并且始终命名为
a.exe
(无需指定)。

Microsoft Windows [Version 10.0.22621.2134]
(c) Microsoft Corporation. All rights reserved.

C:\Users\me\Desktop\Hello World>g++ main.cpp

C:\Users\me\Desktop\Hello World>a.exe

C:\Users\me\Desktop\Hello World>a

C:\Users\me\Desktop\Hello World>

我还尝试过哪些其他事情:

  • 打开我的文件夹中的a.exe文件,该文件立即关闭。我也尝试在 main 方法中添加

    system("pause");
    ,但没有成功。

  • 为输出添加自定义名称,例如

    g++ main.cpp -o hello
    ,带或不带 .exe 后缀。

  • 将 main.cpp 重命名为其他名称,例如 hello.cpp。


我的机器上已按要求安装了G++、GCC和GDB。

C:\Users\me>g++ --version
g++ (Rev2, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\Users\me>gcc --version
gcc (Rev2, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\Users\me>gdb --version
GNU gdb (GDB) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

我们将不胜感激。

c++ windows cmd g++
1个回答
1
投票

谢谢 Acane:问题是由 Inkscape 引起的。卸载 Inkscape 后,一切就开始工作了。谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.