VSCode配置C++环境

本文详细介绍了如何在VSCode中配置C++环境,包括设置字体大小、生成c_cpp_properties.json以定义编译器路径和标准,创建tasks.json来执行编译任务,以及设置launch.json进行调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VSCode配置C++环境

IDE用惯了,换编辑器写被坑傻了。


VSCode环境的配置都由.json数据构成,全部放在workingFolder的.vscode文件夹内,默认是隐藏的,因为这是配置文件啊。

1.配置settings

如果想改字体大小什么的,直接搜索命令open settings,在user.setting里改。

2.生成c_cpp_properties.json

Command shift P + Edit configuration

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"
            ],
            "defines": [],
            "windowsSdkVersion": "10.0.16299.0",
            "compilerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
3. 生成tasks.json

这个文件很重要,在这文件里要说明你想执行的任务。

"tasks": [
        {
            "label": "build", # 这是任务的标签,也就是名字,在run task时会体现
            "type": "shell", # 通过shell运行你的命令
            "command": "g++", # 指定编译器命令,参数作用看我上一篇博客,gcc需要额外链接
            "args": [
            	"first.cpp",
                "test.cpp", # 参数
                "-o",
                "main.exe"
            ]
        },
        {
            "label": "build-debug",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                # 生成可调试文件
                "first.cpp",
                "-o",
                "debug.exe"
            ]
        }
        
    ]
4.生成launch.json

Configure Task Runner,

debug->open configuration,生成launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            # 调用生成的调试文件名字,第二个task生成的
            "program": "${workspaceFolder}/debug.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            # gdb.exe路径
            "miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            # 可以省去debug的第一步
            "preLaunchTask": "build-debug"
        }
    ]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值