- 打开VSCode
- 将工程根目录拖到vscode中(打开)
- shift+command+p打开命令框
- 输入Tasks:configure task
- 选择others
- 这时会自动打开一个tasks.json文件,并且工程根目录下有一个.vscode目录
- 编辑tasks.json文件如下
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build and run",
"type": "shell",
"command": "g++ -o ${workspaceRoot}/your_program_name ${workspaceRoot}/your_file_name.cpp;${workspaceRoot}/your_program_name",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
command+S保存
shift+command+b编译运行