在Linux中,我可以键入集成终端,没问题。我可以输入用户输入,它将输出。在Windows上,我不能这样做。输出显示在调试控制台中,我无法在该控制台或集成终端中键入内容。
在图中,我运行时没有使用C ++进行调试,当我要求输入时,它挂在那里并且没有输出。我看过CodeRunner,但我不愿意使用它。
The picture of the terminal when running.
编辑
{
// 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": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
答案 0 :(得分:0)
默认情况下,C ++程序输出到的调试控制台不不支持用户输入。这意味着C ++程序不会读取在调试控制台中输入的内容。
要解决此问题,请将"externalConsole": false
文件中的行"externalConsole": true
更改为launch.json
,以便您的C ++程序可以在外部控制台中运行。这样,您可以输入用户输入并被正在调试的C ++程序解释。
您的launch.json
现在应该类似于:
{
// 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, // <-- Changed to "true" in here
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
在此处了解更多信息: How to read input when debugging in C++ in Visual Studio Code?