VS Code 中 C++ 项目 json 配置说明

以下是关于 Visual Studio Code 中的 tasks.jsonlaunch.json 文件针对 C++ 项目的详细说明。

tasks.json

tasks.json 文件用于定义自动化任务,比如编译代码。

基本结构
{
   
    
    
    "version": "2.0.0",
    "tasks": [
        {
   
    
    
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${workspaceFolder}/main.cpp",
                "-o",
                "${workspaceFolder}/main"
            ],
            "group": {
   
    
    
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": ["$gcc"]
        }
    ]
}
关键字段说明
  • version: 配置文件版本。
  • tasks: 任务数组