1

I have been trying to figure out how to receive input in Windows vscode c++ program for example using cin. I have already tried running with MingW and cl and both have the same result.

Terminal output is being sent to vscode debugconsole and I can't interact with the program.

The same program runs fine if it is run directly via terminal or cmd command prompt.

Here is my tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cl.exe build active file",
            "type": "shell",
            "command": "c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

And here is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "preLaunchTask": "cl.exe build active file"
        }
    ]
}

I've seen other suggestions like using "code-runner.runInTerminal": true and "terminal": "integrated" but this has not worked for me. I have already seen this other post: Visual Studio Code: Take Input From User

But so far no joy.

Here's a screen of vscode that shows the issue with a small c++ program: enter image description here

You will see from above that the output is directed to the debugconsole pane and no interaction is possible from there.

Whereas, the advice from https://code.visualstudio.com/docs/cpp/config-mingw indicates the IO should go to the terminal pane.

paolov
  • 2,139
  • 1
  • 34
  • 43
  • 1
    Did you read [*How to debug small programs*](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) ? Please show an [MRE] in your question and read [more about C++](https://en.cppreference.com/). Consider using [GCC](http://gcc.gnu.org/) with [GDB](http://www.gnu.org/software/gdb/) – Basile Starynkevitch Jun 03 '20 at 06:17
  • Yes, I have read that and also the vscode guides for setting up C++ and mingw and cl. So far still can't figure out why I can't interact with standard input in vscode – paolov Jun 03 '20 at 06:30
  • Maybe your standard input has been redirected or closed? – Basile Starynkevitch Jun 03 '20 at 06:32
  • @BasileStarynkevitch Are you using c++ and vscode in windows? If so, you should be able to see the issue immediately. I don't think the issue is that of standard input being closed or redirected. – paolov Jun 03 '20 at 07:01
  • Is your program written in [standard C++](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf), or using [Qt](http://qt.io)? In both cases, debugging and developing it under Linux (perhaps in some VM) might be easier. And you could then use the [Clang static analyzer](https://clang-analyzer.llvm.org/). Are you allowed to change your IDE to e.g. [GNU emacs](https://www.gnu.org/software/emacs/) which does run on Windows (and is MinGW friendly) ? **Please [edit](https://stackoverflow.com/posts/62166392/edit) your question to improve it.** – Basile Starynkevitch Jun 03 '20 at 07:08
  • I am hoping to be able to remain in vscode windows. The advice from https://code.visualstudio.com/docs/cpp/config-mingw seems to indicate the IO should go to the terminal pane and not the debugconsole. – paolov Jun 03 '20 at 07:29

0 Answers0