Search code examples
c++visual-studio-codestdvscode-code-runner

Where is std::cin when std::cout is going to the "Output" pane of VSCode


When I do a "Run Code" command in Visual Studio Code in Windows (it's the first option when I right-click in the editor), the std::cout output goes to the "Output" pane of VSCode. But when this happens, where is std::cin? You can't type in the "Output" pane, and the code hangs at any cin lines.

Is there some other place that's working as std::cin when I run this way? And if not, is there some way to configure the "Run Code" command so that cin and cout go to a terminal? I've already tried editing the console argument of settings.json, like the first solution to this github issue (or its latest equivalent, since the externalConsole option is deprecated), but it doesn't help, I think because output just isn't going to any console at all.

(also, the "Run Code" command does not enter a debugging session, just compiles and executes. Regular debugging works fine and cin and cout go to the terminal specified in settings.json)


Solution

  • what you say is provided with two extension of VSCode.

    • The "Run Code" command in right click menu is likely provided by extension Code Runner
    • The 'settings.json' and the issue talks about the Microsoft's official C/C++ support extension C/C++

    For you case, you may need to set this setting for Code Runner if you want to use the stdin of process

    "code-runner.runInTerminal": true,