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": "${workspaceFolder}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "preLaunchTask": "build",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
        
    ]
}

test.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "gcc",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.out",
                "-g",
                "-static-libgcc",
                "-std=c99"
            ],
            "type": "shell",
            "group": "build",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared"
            },
            "problemMatcher": "$gcc"
        },
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "group": {
                "kind": "build",
                "isDefault": true
              }, 
            "args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
        }
    ]
}

其他运行方式

C++(方法3:使用C/C++ Compile Run插件)

VSCode的这个插件更简单,但只能用于单文件
C/C++ Compile Run下载
这下根本无需配置task.json和launch.json,保存后直接按F6自动编译运行,其他功能见插件下载页的how to use

更多推荐