VS code运行C和C++的环境配置

本文详细介绍了如何配置C++的开发环境,包括c_cpp_properties.json用于设置编译器路径和包含目录,launch.json用于调试配置,settings.json调整文件关联和错误提示,以及tasks.json用于构建任务。通过这些配置,开发者可以高效地在Windows上进行C++编程和调试。

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

c_cpp_properties.json文件:
注:XXXXXX 代表的是文件路径中文件夹的名字

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "D:\\XXXXXX\\XXXXXX\\Dev-Cpp\\MinGW64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include",
                "D:\\XXXXXX\\XXXXXX\\Dev-Cpp\\MinGW64\\include",
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\5_360Downloads\\360Downloads\\Dev-Cpp\\MinGW64\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
            
        }
    ],
    "version": 4
}
launch.json文件中:
注:XXXXX代表文件路径中的文件夹名字

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true, //false
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\XXXXX\\XXXXX\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++"
        }
    ]
}
settings.json文件中:

{
    "files.associations": {
        "ostream": "cpp",
        "iostream": "cpp"
    },
    "C_Cpp.errorSquiggles": "Disabled"
}
tasks.json文件中:


{
    "version": "2.0.0",
    "tasks": [
        {
            //"label": "build",
            "label": "g++",    //修改此项
            "type": "shell",
            //"command": "msbuild",
            "command":"g++.exe",
            /*"args": [
                // Ask msbuild to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                "/t:build",
                // Do not generate summary otherwise it leads to duplicate errors in Problems panel
                "/consoleloggerparameters:NoSummary"
            ],*/
            "args": [
                "-g",
                //"${workspaceFolder}/include/*.cpp", //要包含所有需要执行的cpp,包含自定义头文件对应的cpp(好像没什么影响,将头文件放在当前目录就行)
                "-fexec-charset=GBK",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-Wall",
                "-static-libgcc"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

测试结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值