类型:调试器
我的主要问题是无法 将输入传递给 std::cin 使用 C++ 的 VSCode 调试工具。我尝试了我在网上找到的不同东西,主要是启用
"externalConsole":true
在 launch.json
,但徒劳无功。事实上,当我这样做时,会出现一个外部控制台,但它似乎“被窃听了”,因为它有一个闪烁的光标,但是当我写入它时,没有任何 react 。 这是“被窃听的”外部控制台的屏幕截图:
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<bits/stdc++.h>
using namespace std;
int main()
{
cout << "Hello";
string name;
cin >> name;
cout << "Hello " << name;
return 0;
}
最佳答案
只需在 中执行“ externalConsole ”:true launch.json 下 .vscode 在您的工作目录中。
之后会出现一个外部终端窗口,在 CIN 上点击 STEP OVER 后输入输入!
关于c++ - 在 VSCode 中调试 C++ 期间将输入传递给 std::cin 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60443322/