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

如何设置VS Code将Windows环境下C程序运行输出显示到TERMINAL面板

方案1:将C程序输出直接定向到TERMINAL面板(推荐)

你只需要修改launch.json配置,添加console参数指定输出目标即可。在你现有的configurations配置块中新增一行:

"console": "integratedTerminal"

修改完成后的完整launch.json参考如下:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "console": "integratedTerminal", // 新增的配置行
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe build active file"
        }
    ]
}

保存配置后重新运行程序,所有程序输出会直接显示在TERMINAL面板,无需再手动切换DEBUG CONSOLE。

方案2:保持DEBUG CONSOLE激活状态,不自动跳转面板

如果你仍希望输出显示在DEBUG CONSOLE,不想每次运行都自动切到TERMINAL,可以在launch.json的配置块中添加以下参数:

"console": "internalConsole",
"presentation": {
    "reveal": "never",
    "focus": false
}

保存配置后重新运行,面板不会自动切换到TERMINAL,DEBUG CONSOLE会保持激活状态。


内容的提问来源于stack exchange,提问作者JJJohn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 08:15:04