首页 > 解决方案 > 在 VSCode 中调试 C++ 期间将输入传递给 std::cin 的问题

问题描述

类型:调试器

这是“错误”外部控制台的屏幕截图:

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;
}

标签: c++debugginginputvisual-studio-code

解决方案


只需在工作目录中的.vscode下的launch.json中执行“ externalConsole ”:true即可。之后会出现一个外部终端窗口,在 CIN 上点击 STEP OVER 后输入输入!


推荐阅读