类型:调试器
操作系统:Windows 10
VS Code 版本:1.42.1
C/C++ 扩展版本:0.26.3
未安装其他扩展程序
错误的清晰简洁描述:
我遇到的主要问题是无法通过 VSCode 的 C++ 调试工具向 std::cin 输入内容。我尝试了网上找到的不同方法,其中一个主要方法是在 launch.json 中启用 "externalConsole":true,但都没有成功。实际上,当我这样做时,会出现一个外部控制台,但似乎 '存在缺陷',因为它有一个闪烁的光标,但当我在其中输入时,什么也不发生。
以下是 '存在缺陷' 的外部控制台截图:
https://imgur.com/a/sVA6LCJ
以下是我的 launch.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": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
这是我正在尝试执行的代码示例:
#include
using namespace std;
int main()
{
cout << "Hello";
string name;
cin >> name;
cout << "Hello " << name;
return 0;
}