Mohamed Aziz Tousli
Mohamed Aziz Tousli

Reputation: 63

Problem with passing input to std::cin during debugging C++ in VSCode

Type: Debugger

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

Upvotes: 5

Views: 3825

Answers (2)

Unkownn
Unkownn

Reputation: 53

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!

Upvotes: 4

Mohamed Aziz Tousli
Mohamed Aziz Tousli

Reputation: 63

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

Upvotes: 1

Related Questions