5

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://i.sstatic.net/RkrT6.jpg

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;
}
4
  • Have you always had this problem with cin? When was the last time cinworked in VS? Commented Feb 27, 2020 at 23:53
  • Actually cin works fine in 'normal' mode (without the debugging tool). The problem occurs when I use the debugging tool. Commented Feb 28, 2020 at 0:09
  • That's maddening. I'd just aim to reinstall and hope that fixes it. Commented Feb 28, 2020 at 0:10
  • I'll consider that as a last option. Thank you anyway. Commented Feb 28, 2020 at 0:11

2 Answers 2

4

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!

Sign up to request clarification or add additional context in comments.

Comments

1

Problem solved. I just needed to step over in VSCode debug interface so that the external console let me write in it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.