首页 > 解决方案 > 内部调试控制台不接受我的输入

问题描述

当我在内部调试控制台(例如数字)中输入我的输入时,我收到消息“无法执行此操作,因为进程正在运行”。(输出没有问题),但是当我在launch.json中切换外部控制台(Windows控制台)时,我没有遇到任何问题。

我已经阅读了一些关于 VSC 中调试的纪录片(例如 code.visualstudio.com/Docs/editor/debugging),但没有任何内容。我不应该在那里输入输入吗?另外,我的输出只显示在调试控制台中,这也正常吗?我也无法通过终端输入我的输入。即使我开始没有调试情况也不会改变。如果我使用扩展名“C/C++ Compile Run”,则会创建正常的内部终端,我可以与之交互。

我的 launch.json 配置

        "name": "g++.exe build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "internalConsoleOptions": "openOnSessionStart",
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "g++.exe build active file"

我的任务.json:

  "type": "shell",
  "label": "g++.exe build active file",
  "command": "C:\\MinGW\\bin\\g++.exe",
  "args": [
    "-g",
    "${file}",
    "-o",
    "${fileDirname}\\${fileBasenameNoExtension}.exe"
  ],
  "options": {
    "cwd": "C:\\MinGW\\bin"
  },
  "problemMatcher": [
    "$gcc"
  ],
  "group": {
    "kind": "build",
    "isDefault": true
  }

c_cpp_properties.json:

        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "windowsSdkVersion": "10.0.17763.0",
        "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "msvc-x64"

标签: visual-studio-code

解决方案


据我所知,调试控制台不支持从 C++ 程序中的控制台读取输入。唯一可能的解决方案是通过将externalConsole属性设置为true来使用外部终端。

官方文档说要配置控制台属性为集成终端来进行 Node.js 编程。但是对于 c++ 程序没有这样的规定。

Go 编程也有类似的未解决问题。可能是 vscode 团队会在他们的 backlog 中有这个。


推荐阅读