vscode c++开发环境搭建

41 阅读1分钟
  1. 安装c/C++插件

image.png

2.打开一个保护.cpp文件的文件夹(没有就自己创建)

“command+shift+p”打开命令行工具窗口,输入或者选择“
Edit Configurations”命令。配置c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Developer/CommandLineTools/usr/include/c++/v1",
                "/usr/local/include",
                "/Library/Developer/CommandLineTools/usr/include",
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}

配置tasks.json

{ 
"version": "2.0.0", 
"tasks": [ 
{ 
"label": "c++", 
"command": "clang++",
"type": "shell",
"args": [ "./c++/hello.cpp", "-std=c++11", "-g" ],
"presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" } }
]
}

配置launch.json

{
  // 使用 IntelliSense 了解相关属性。 
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "c/c++ Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/a.out",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "lldb",
      "preLaunchTask": "c++"
    }
  ]
}