VScode搭建c++环境文件配置

VScode搭建c++环境,折腾了半天,首先要下载MinGW并配置环境变量,在cmd里输入g++ --version看是否成功,其次最重要的就是.vscode下面的那几个文件,耗费了半天力气就在这几个文件上,包括:

  1. c_cpp_properties.jaon
  2. launch.json
  3. tasks.json

c_cpp_properties.jaon

{
    "configurations": [
        {
            "name": "Win32",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++" //修改为 c++安装路径
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "includePath": [
                "${workspaceFolder}",
                "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++" //修改为 c++安装路径,同上
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGW\\bin\\gcc.exe", //修改为 gcc.exe路径
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //修改为gdb.exe路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Compile",
        }
    ]
}

tasks.jaon

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile", //和launch.json中的"preLaunchTask"相对应
            "type": "shell",
            "command": "g++",
            "args": [
                        "-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}.exe",
                    ],  
            "presentation": {
                "reveal": "always",
                "panel": "shared",
                "focus": false,
                "echo": true
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": "absolute",
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
  ]
}

你可能感兴趣的:(VScode搭建c++环境文件配置)