vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

VsCode C++ cin commands not working in debug console

Open rafid149 opened this issue 4 years ago • 11 comments

I couldn't use cin command in c++ when debugging because we can't input something in debug console. After that I saw so many people said to use "externalconsole": true but after that, the console closes as soon as the program finishes execution. I heard we can use a cin command at the end of the CPP file but it is very annoying that we always have to write cin command at the end. So how can I fix it? Is there any way to use integrated terminal instead of debug console? Btw I am talking about Cygwin Gcc

rafid149 avatar Jun 15 '21 08:06 rafid149

You should be able to input data with "externalconsole": false in the terminal tab. Debug Console is used for Expression Evaluation, GDB Commands or engine logs.

image

WardenGnaw avatar Jun 15 '21 17:06 WardenGnaw

@WardenGnaw This doesn't work in macOS, at least for me, I always have to use "externalConsole": true for debugging programs that use std::cin. Also, it's posible to use iTerm.app as the default terminal instead of Terminal.app? I have changed this setting "terminal.external.osxExec": "iTerm.app" but doesn't seem to work in debugging.

lucasaf04 avatar Jun 16 '21 11:06 lucasaf04

@lucasaf04 The macOS issue is tracked at https://github.com/microsoft/vscode-cpptools/issues/5079.

This issue here was with Cygwin, and it is used for Windows and externalConsole is possible in this scenario.

Also, it's posible to use iTerm.app as the default terminal instead of Terminal.app?

The externalConsole is not controlled by VS Code and that option is not propagated to the debugger. Because iTerm.app is not a default application, it is currently hard coded to use Terminal.app.

See https://github.com/microsoft/MIEngine/blob/9072ed87a5d9a14303aebbb074664cfbab88fc19/src/MICore/osxlaunchhelper.scpt#L11

WardenGnaw avatar Jun 16 '21 17:06 WardenGnaw

This issue here was with Cygwin, and it is used for Windows and externalConsole is possible in this scenario.

Ohh. Sorry. So I would never be able to debug “cin programs” on macOS using integrated terminal?

Hope #5079 gets fixed soon.

lucasaf04 avatar Jun 16 '21 17:06 lucasaf04

Nope it is not working still. This is my cpp code:

#include <iostream> int main() { int a; std::cin >> a; std::cout << a << std::endl; return 0; }

the code is showing in one line in the forum for some reasons I don't know well when I try to type input in the terminal ( I typed 5 three times and pressed enter because it didn't show in terminal )

it doesn't show in terminal and after stop debugging there was something like this command-----

$  /usr/bin/env c:\\Users\\User\\.vscode\\extensions\\ms-vscode.cpptools-1.4.1\\debugAdapters\\bin\\WindowsDebugLauncher.exe --
stdin=Microsoft-MIEngine-In-1kaltmip.ot3 --stdout=Microsoft-MIEngine-Out-hqhnwyp4.nus --stderr=Microsoft-MIEngine-Error-gbgj4wu
t.aya --pid=Microsoft-MIEngine-Pid-gywiyai2.5yw --dbgExe=D:\\ConsoleEmulators\\Cygwin\\Cygwin\\bin\\gdb.exe --interpreter=mi

User@User-PC ~
$ 5
bash: 5: command not found

User@User-PC ~
$ 5
bash: 5: command not found

User@User-PC ~
$

rafid149 avatar Jun 18 '21 04:06 rafid149

Oh it worked when I deleted the path of cygwin g++ and added the Code::Blocks mingw bin path. I think the error is happening because of Cygwin gcc 11 glitch because I used gcc 11 test version :smiley_cat: :smiley_cat: :smiley_cat: :smiley_cat:

rafid149 avatar Jun 22 '21 08:06 rafid149

Hey i changed cygwin gcc version, but it is still not working ....

rafid149 avatar Jul 25 '21 03:07 rafid149

https://www.youtube.com/watch?v=UPda5iNot-k

Usagicodes avatar Oct 29 '23 15:10 Usagicodes

@Usagicodes Your solution was helpful Thank you :)

Bchan725 avatar Oct 30 '23 08:10 Bchan725

change the settings of VS code env. Click on the Settings (gear wheel) on bottom left panel

Settings -> Extensions -> Run Code Configuration -> Run In Terminal (check the box).

Save and run the code.

veebee17 avatar Jul 24 '24 06:07 veebee17

I update the libstdc++, get the things done, maybe just luck.

VectorYQ avatar May 29 '25 01:05 VectorYQ