以前,当我尝试使用 C/C++ 扩展和 MinGW32 的 g++ 和 gdb 在 Windows 10 上的 VSCode 中进行调试时,我能够按 F5(默认的“开始调试”热键),设置我的 tasks.json 和 launch.json ,并且程序的输出将出现在集成终端中,以及任何输入提示。这很有用,尤其是当我需要在为学校作业调试程序时还为程序提供输入,而无需打开外部 shell。但是,情况不再如此,我很困惑为什么,因为我没有主动更改任何内容来导致这种情况发生,现在所有程序输出都出现在调试控制台中,我无法输入输入。我更愿意将事情恢复到我上面描述的内容,所有输出/输入都发生在集成终端中,但我 我不确定我将如何做到这一点。我也尝试使用可用的 Python 扩展在 VSCode 中调试 Python 程序,但打印语句的输出出现在集成终端中,我希望它出现在其中。此外,Code Runner 扩展适用于我当前的问题,但我更愿意将我的工作环境恢复到之前的状态。我当前的VSCode版本是1.49.2,我的C/C++扩展版本是1.0.1,我的Python扩展版本是2020.9.111407。我也在使用 g++.exe (MinGW.org GCC Build-20200227-1) 9.2.0 和 GNU gdb (GDB) 7.6.1 Code Runner 扩展适用于我当前的问题,但我更愿意将我的工作环境恢复到之前的状态。我当前的VSCode版本是1.49.2,我的C/C++扩展版本是1.0.1,我的Python扩展版本是2020.9.111407。我也在使用 g++.exe (MinGW.org GCC Build-20200227-1) 9.2.0 和 GNU gdb (GDB) 7.6.1 Code Runner 扩展适用于我当前的问题,但我更愿意将我的工作环境恢复到之前的状态。我当前的VSCode版本是1.49.2,我的C/C++扩展版本是1.0.1,我的Python扩展版本是2020.9.111407。我也在使用 g++.exe (MinGW.org GCC Build-20200227-1) 9.2.0 和 GNU gdb (GDB) 7.6.1
为了获得最大的清晰度,通过手动键入 g++ 和 gdb 命令从集成终端进行编译和调试工作正常,但 F5 不再产生我期望的行为。
我已确保我的 launch.json 正确设置了“externalConsole”:false,我的 Terminal:Explorer Kind 设置设置为“integrated”,并且 Terminal > Integrated:Inherit Env 设置为 true。我尝试切换所有这些选项,在管理员模式下运行,在 Windows 8 的兼容模式下运行,回滚到我正在使用的扩展的旧版本,但没有任何改变这种行为。
任务.json:
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Programming\\MinGW32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
启动.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Programming\\MinGW32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
测试.cpp:
#include <iostream>
using namespace std;
int main() {
cout << "Hello\n";
system("pause");
return 0;
}
这就是我在 python 文件上按 F5 时发生的情况,这是我所期望的那种行为。
这就是我在我的 cpp 文件上按 F5 时发生的情况,集成终端中没有输出。
由于其简单性,我选择在第一张图片中省略我的 .py 文件中的代码
更新(2020 年 9 月 28 日):显然此问题已在此处记录,对我有用的解决方案是从他们的 sourceforge 安装mingw-w64,然后在系统环境变量中更新我的 mingw 路径。