You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code调试C程序时无法输出内容或接收输入的问题求助

VS Code调试C程序时无法输出内容或接收输入的问题求助

各位好,我在VS Code里调试C程序时遇到了棘手的问题,具体情况如下:

我的项目.vscode文件夹下有四个文件:c_cpp_properties.json、extensions.json、launch.json、tasks.json,其中三个核心配置文件的内容如下:

launch.json

{
    "configurations": [
        {
            "name": "C/C++: gcc.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe build active file"
        }
    ],
    "version": "2.0.0"
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22621.0",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "C:/MinGW/bin/gcc.exe"
        }
    ],
    "version": 4
}

我用来测试的C代码非常简单:

#include <stdio.h>
int main(){
int i;
scanf("%d", &i);
printf("You entered: %d\n", i);
return 0;
}

按下F5启动调试后,终端显示的内容为:

PS C:\Users\***\OneDrive\Documents\INTERVIEW PREP\DSA and Small Learnings>  & 'c:\Users\****\.vscode\extensions\ms-vscode.cpptools-1.23.0-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-caznmueg.sx2' '--stdout=Microsoft-MIEngine-Out-kpfaclzx.m3o' '--stderr=Microsoft-MIEngine-Error-nq1rgwan.vxy' '--pid=Microsoft-MIEngine-Pid-d12jsuyv.lf0' '--dbgExe=C:\MinGW\bin\gdb.exe' '--interpreter=mi' 

现在的具体问题:

  • 调试时程序既不输出内容,遇到scanf也无法接收输入。比如调试器停在scanf行时,按F10步进完全没反应,只能通过鼠标 hover 查看变量值。
  • 如果调试器没停在scanf上,程序会卡在等待输入的状态,但我输入内容回车后毫无变化,调试器也无法继续步进。直到手动停止调试器,刚才输入的内容才会立刻出现在终端里——比如我输入fffff然后停止调试,这个字符串就直接在终端里执行了。

我已经安装了C/C++扩展套件、CodeLLDB和Code Runner扩展,还是没能解决问题,有没有大佬能帮忙分析一下原因?

备注:内容来源于stack exchange,提问作者Aditya N Panchal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 08:48:07