VSCode配置C/C++环境教程

新建项目文件夹,在文件夹下,创建.vscode文件夹,在.vscode文件夹中包含了三个文件c_cpp_properties.json、launch.json、tasks.json。
类似于下图这样(注:所有路径中的名称不能带中文):
VSCode配置C/C++环境教程_第1张图片
VSCode配置C/C++环境教程_第2张图片

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:/SettingSoftware/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json:

{
    "version": "0.2.0",
    "configurations": [  {
        "name": "(Windows) Launch",
        "type": "cppvsdbg",
        "request": "launch",
        "console":"none",
        "program": "C:/Windows/System32/cmd.exe",
        "args": [
            "/C",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "&",
            "pause"
        ],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole":true //打开新窗口,方便输入数据

    },  {
            "name": "(gdb) Launch",
            "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
            "type": "cppdbg",//配置类型,只能为cppdbg
            "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
            "program": "C:/Windows/System32/cmd.exe",
            "args": [
            "/C",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "&",
            "pause"],//调试传递参数
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\SettingSoftware\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",//任务的名字,就是刚才在命令面板中选择的时候所看到的,可以自己设置
            "command": "D:\\SettingSoftware\\mingw64\\bin\\g++.exe",
            "args": [//编译时候的参数
                "-g",//添加gdb调试选项
                "${file}",
                "-o",//指定生成可执行文件的名称
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:/SettingSoftware/mingw64/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true//表示快捷键Ctrl+Shift+B可以运行该任务
            }
        }
    ]
}

你可能感兴趣的:(安装,笔记,C++,python,c/c++环境配置)