提问人:gluon 提问时间:10/30/2023 最后编辑:user4581301gluon 更新时间:10/31/2023 访问量:63
C++文件不给出任何输出,可能与Windows相关的问题有关
C++ file doesn't give any output, possibly related to Windows-related problem
问:
我编写了以下简单的代码来习惯使用C++,但是它不能在我的计算机上使用,即使它适用于在线编译器 https://www.programiz.com/cpp-programming/online-compiler/
#include <iostream>
int main() {
int x, y;
std::cout << "Type a number: ";
std::cin >> x;
std::cout << "Type another number: ";
std::cin >> y;
int sum = x + y;
std::cout << "Sum is: " << sum;
return 0;
}
我尝试在计算机终端上使用 g++ 文件名.cpp运行它,并在 VSCode 终端上运行它。我期望的是,我得到输出 Type a number: 打印在终端上,然后等待输入,然后键入另一个 number:,再次等待输入;然后打印两个数字的总和。g++ filename.cpp
然而,我得到的是以下内容:
PS C:\Users\49155\OneDrive\Masaüstü> g++ filename.cpp
PS C:\Users\49155\OneDrive\Masaüstü>
在两个航站楼。它不打印任何东西,不等待任何输入,不做任何事情。该文件在存储库中,因此我认为问题与路径无关。
我使用的是 Windows,由于代码在在线编译器上运行,因此我认为问题与代码无关,而是与计算机有关。我已经在 VSCode 中拥有 C++ 扩展,为了检查 C++ 版本,我在终端中进行了检查,结果如下:\Masaüstü
g++ -v
PS C:\Users\49155\OneDrive\Masaüstü> g++ -v
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-12.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev10, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Rev10, Built by MSYS2 project)
有谁知道为什么我不能运行它?
答: 暂无答案
评论
main()