配置环境
-
在Extension里面找到C/C++插件并下载
-
找到code runner安装
-
在终端输入
clang --version检查是否已将安装clang -
打开vscode, 新建一个文件夹,编写一个简单的helloworld.cpp文件保存在此文件夹下
-
shift + command + P( 输入shell, 选择install'code' command in PATH)
-
shift + command + B (编译)
-
打开terminal, 点击 configure default build task(会生成tasks.json) 可以讲自动生成的内容换成官方文档的
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- You can modify your
tasks.jsonto build multiple C++ files by using an argument like"${workspaceFolder}/*.cpp"instead of${file}. This will build all.cppfiles in your current folder. You can also modify the output filename by replacing(将${file}替换即可)