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

VS Code终端输出^C问题求助:C++编译运行后重复出现该字符

解决VS Code C++终端反复出现^C的问题

1. 修改调试配置文件(launch.json)

打开调试面板点击齿轮图标,调出launch.json,调整以下设置:

  • 切换externalConsole的取值(true/false),不同控制台模式可能避免进程残留:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false, // 切换为true再测试一次
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }
    ]
}

2. 调整终端设置

VS Code内置PowerShell的shell集成可能导致标记残留:

  • 打开设置,搜索terminal.integrated.shellIntegration.enabled,将其设置为false后重启VS Code。
  • 或直接在终端执行$ErrorActionPreference = 'Stop',避免错误状态残留。

3. 优化编译任务配置(tasks.json)

打开tasks.json,添加presentation设置,每次运行前清空终端:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": ["$gcc"],
            "group": {"kind": "build", "isDefault": true},
            "presentation": {
                "clear": true, // 每次运行前清空终端
                "reveal": "always"
            }
        }
    ]
}

4. 彻底清理进程与缓存

  • 关闭所有VS Code窗口,打开任务管理器,结束Code.exe、WindowsDebugLauncher.exe等相关进程。
  • 进入C:\Users\<你的用户名>\AppData\Roaming\Code目录,删除Cache和CachedData文件夹,再重启VS Code。

5. 更换终端类型

将内置终端切换为Command Prompt或Git Bash尝试:

  • 打开设置,搜索terminal.integrated.defaultProfile.windows,选择其他终端类型,重启后测试编译运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 14:04:51