在VSCode中调试C ++时将输入传递给std :: cin的问题

问题描述 投票:1回答:1

类型:调试器

  • OS:Windows 10
  • VS代码版本:1.42.1
  • C / C ++扩展版本:0.26.3
  • 未安装其他扩展程序
  • 关于此错误的简要说明:我遇到的主要问题是无法使用C ++的VSCode调试工具将输入传递到std :: cin。我尝试了在网上发现的其他事情,主要是在"externalConsole":true中启用launch.json,但徒劳无功。实际上,当我这样做时,会出现一个外部控制台,但由于光标闪烁,所以似乎是“错误的”,但是当我写进去时,什么也没发生。

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

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++ debugging input visual-studio-code
1个回答
1
投票

问题已解决。我只需要进入VSCode调试界面,以便外部控制台可以在其中编写代码。

© www.soinside.com 2019 - 2024. All rights reserved.