Answer a question

Type: Debugger

  • OS: Windows 10
  • VS Code Version: 1.42.1
  • C/C++ Extension Version: 0.26.3
  • No other extensions installed
  • A clear and concise description of what the bug is: The main issue that I have is the inability to pass input to std::cin using VSCode debugging tool for C++. I tried different things that I found online, the main one was enabling "externalConsole":true in the launch.json, but in vain. In fact, when I do that, an external console appears, but it seems 'bugged', since it has a blinking cursor, but when I write into it, nothing happens.

Here is a screenshot of the 'bugged' external console:

https://imgur.com/a/sVA6LCJ

Here is my launch.json configuration:

{
    // 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"
        }
    ]
}

Here is the code sample that I am trying to execute:

#include<bits/stdc++.h>
using namespace std;
int main() 
{
    cout << "Hello";
    string name;
    cin >> name;
    cout << "Hello " << name;
    return 0;
}

Answers

Just do "externalConsole":true in the launch.json under the .vscode in your working directory. After that an external Terminal Window will appear, enter the input after you hit STEP OVER while on CIN!

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐