c++ - 在 VSCode 中调试 C++ 期间将输入传递给 std::cin 的问题
问题描述
类型:调试器
- 操作系统:Windows 10
- VS 代码版本:1.42.1
- C/C++ 扩展版本:0.26.3
- 没有安装其他扩展
- 对错误的清晰简洁的描述:我遇到的主要问题是无法使用 C++ 的 VSCode 调试工具将输入传递给 std::cin 。我尝试了我在网上找到的不同的东西,主要的是在 中启用
"externalConsole":true
,launch.json
但徒劳无功。事实上,当我这样做时,会出现一个外部控制台,但它似乎“有问题”,因为它有一个闪烁的光标,但是当我写入它时,什么也没有发生。
这是“错误”外部控制台的屏幕截图:
这是我的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;
}
解决方案
只需在工作目录中的.vscode下的launch.json中执行“ externalConsole ”:true即可。之后会出现一个外部终端窗口,在 CIN 上点击 STEP OVER 后输入输入!
推荐阅读
- python - 从python中的列表中提取特定的字符串/单词
- javascript - Keycloak Script 基本身份验证器在失败时出现相同的错误消息
- python - Python - 在 FTP 中按块上传内存文件(由 API 调用生成)
- c++ - 将 shared_ptr 与 FreeRTOS 队列一起使用
- excel - 多个条件范围内条件的多个 Sum 范围求和
- cucumber - 黄瓜水豚中的换行符
- raspberry-pi - pi-zero usb otg 端口在引导期间被识别为未知设备
- excel - MDX Excel 中的 IIF + 过滤器 + inst 函数
- ios - 具有 Swift 4 依赖项的 Swift 3 Cocoapod
- symfony - Doctrine 2 实体关系:级联合并