microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

VsCode C++ cin commands not working in debug console #7699

Open rafid149 opened 3 years ago

rafid149 commented 3 years ago

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

WardenGnaw commented 3 years ago

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

lucasaf04 commented 3 years ago

@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.

WardenGnaw commented 3 years ago

@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

lucasaf04 commented 3 years ago

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.

rafid149 commented 3 years ago

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

`

include

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 commented 3 years ago

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 commented 3 years ago

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

Usagicodes commented 11 months ago

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

byungchan0725 commented 11 months ago

@Usagicodes Your solution was helpful Thank you :)

veebee17 commented 2 months ago

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.