不用图形化也可以直接把launcher.json c_c++_properties.json task.json复制到项目里
首先打开 vscode创建项目
ctrl+shift+p 打开c/c++ edit configuration UI 配置生成c_cpp_properties.json文件

这里选择gcc为 c运行环境 只需要改配置名称跟编译器路径两处其他默认


选g++为c++环境 可以两者都支持最后配置完的样式 c_cpp_properties.json
- {
- "configurations": [
- {
- "name": "linux-gcc-x64",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "compilerPath": "/usr/bin/gcc",
- "cStandard": "${default}",
- "cppStandard": "${default}",
- "intelliSenseMode": "linux-gcc-x64",
- "compilerArgs": [
- ""
- ]
- },
- {
- "name": "c++",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "defines": [],
- "compilerPath": "/usr/bin/g++",
- "cStandard": "c17",
- "cppStandard": "gnu++17",
- "intelliSenseMode": "linux-gcc-x64"
- }
- ],
- "version": 4
- }
二、生成task文件随便选一个c 或者c++文件选configure task 然后配置会生成task.json文件

- {
- "version": "2.0.0",
- "tasks": [
- {
- "type": "cppbuild",
- "label": "C/C++: gcc 生成活动文件",
- "command": "/usr/bin/gcc",
- "args": [
- "-fdiagnostics-color=always",
- "-g",
- "${workspaceFolder}/*.c",
- "-o",
- "${workspaceFolder}/${workspaceRootFolderName}"
- ],
- "options": {
- "cwd": "${fileDirname}"
- },
- "problemMatcher": [
- "$gcc"
- ],
- "group": "build",
- "detail": "编译器: /usr/bin/gcc"
- }
- ,
- {
- "type": "cppbuild",
- "label": "C/C++: g++ 生成活动文件",
- "command": "/usr/bin/g++",
- "args": [
- "-fdiagnostics-color=always",
- "-g",
- "${workspaceFolder}/*.cpp",
- "-o",
- "${workspaceFolder}/${workspaceRootFolderName}"
- ],
- "options": {
- "cwd": "${fileDirname}"
- },
- "problemMatcher": [
- "$gcc"
- ],
- "group": "build",
- "detail": "编译器: /usr/bin/g++"
- }
-
- ]
- }
三、生成debug 环境 luanch.json
- {
- "version": "0.2.0",
- "configurations": [
- {
- "name": "C/C++ Runner: Debug Session",
- "type": "cppdbg",
- "request": "launch",
- "args": [],
- "stopAtEntry": false,
- "externalConsole": false,
- "cwd": "/home/denghg/dhg/C++Work/c++work",
- "program": "${workspaceFolder}/${workspaceRootFolderName}",
- "MIMode": "gdb",
- "miDebuggerPath": "gdb",
- "setupCommands": [
- {
- "description": "Enable pretty-printing for gdb",
- "text": "-enable-pretty-printing",
- "ignoreFailures": true
- }
- ]
- }
- ]
- }
四、最后的项目结构
setting.json是默认生成的