注意 c++11 标准
c_cpp_properties.json配置
{"configurations": [{"name": "Mac","includePath": ["${workspaceFolder}/**"],"defines": [],"macFrameworkPath": ["/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"],"compilerPath": "/usr/bin/clang"}],"version": 4}
注意:若使用 OpenCV,需要在 includePath 添加本地安装 OpenCV 的路径,可参考该链接 vscode c++ code runner 配置 opencv
tasks.json配置用于编译
注意此处 “-std=c++11” 是关键
{"tasks": [{"type": "cppbuild","label": "C/C++: clang++ 生成活动文件","command": "/usr/bin/clang++","args": ["-fdiagnostics-color=always","-g","-std=c++11","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "调试器生成的任务。"}],"version": "2.0.0"}
launch.json配置用于运行
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: /fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "clang++ - 生成和调试活动文件","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": false,"MIMode": "lldb","preLaunchTask": "C/C++: clang++ 生成活动文件"}]}
.7.14 更新
mac 在使用 VSCode 调试 C++ 时,无法输入,下载 CodeLLDB 插件,更改 launch.json 如下。
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: /fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "clang++ - 生成和调试活动文件","type": "lldb","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"cwd": "${fileDirname}",},// {//"name": "clang++ - 生成和调试活动文件",//"type": "cppdbg",//"request": "launch",//"program": "${fileDirname}/${fileBasenameNoExtension}",//"args": [],//"stopAtEntry": false,//"cwd": "${fileDirname}",//"environment": [],//"externalConsole": false,//"MIMode": "lldb",//"preLaunchTask": "C/C++: clang++ 生成活动文件"// }]}
参考链接🔗
.7.31 更新
显示 Debug Shortcut