如何在 Windows 中输入 VS Code 的集成终端?

How to type into the integrated terminal on VS Code in Windows?

在 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"
        }
    ]
}

默认情况下,C++ 程序输出到的调试控制台支持用户输入。这意味着 C++ 程序不会读取在调试控制台中键入的输入。

要解决此问题,请将 launch.json 文件中的行 "externalConsole": false 更改为 "externalConsole": true,以便您的 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"
        }
    ]
}

在此处阅读更多内容: