赞
踩
目录
检查系统是否安装了 clang
clang --version
如果没有安装,则执行
xcode-select --install
- #include <iostream>
- #include <vector>
- #include <string>
-
- using namespace std;
-
- int main() {
-
- vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
-
- for(const string& word : msg) {
- cout << word << " ";
- }
- cout << endl;
-
- }
选择 Terminal > Configure Default Build Task.
在 .vscode
下会创建一个 tasks.json
文件,如下:
- {
- "version": "2.0.0",
- "tasks": [
- {
- "type": "shell",
- "label": "C/C++: 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
- }
- }
- ]
- }
选择 Terminal-> Run Build Task.
选择 Run > Add Configuration... 选择 C++ (GDB/LLDB)
在 .vscode
下会创建一个 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": "Launch (lldb)",
- "type": "cppdbg",
- "request": "launch",
- "program": "${fileDirname}/${fileBasenameNoExtension}",
- "args": [],
- "stopAtEntry": true,
- "cwd": "${workspaceFolder}",
- "environment": [],
- "externalConsole": false,
- "MIMode": "lldb"
- }
- ]
- }
选 Run > Start Debugging 开始 debug
选择 View-> Command Palette... 选 C/C++: Edit Configurations (UI) 如下:
在 .vscode
下会创建一个 c_cpp_properties.json
文件,可以根据需要修改配置。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。