哭辽,Typora里面最好不要插入表情,否则保存会闪退c++
在扩展里面下载c/c++shell
⬆+com+p 打开命令模式:选择c/c++: 编辑配置(edit configuration)
而后再自动生成的.vscode目录,打开c_cpp_properties.json。利用老哥的文件示例:json
{ "configurations": [ { "name": "Mac", "includePath": [ "${workspaceFolder}/**", "/Library/Developer/CommandLineTools/usr/include/c++/v1", "/usr/local/include", "/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include", "/Library/Developer/CommandLineTools/usr/include" ], "defines": [], "macFrameworkPath": [ "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks", "/System/Library/Frameworks", "/Library/Frameworks" ], "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
将要用到的库添加到includePath里面工具
[⇧⌘P]打开命令模式,选择[Tasks: Configure Task]命令,选择的模板为MSBuild,回车后会自动在.vscode目录下生成一个tasks.json文件,下面给出个人文件示例:ui
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build c++", "type": "shell", "command": "g++", "args": [ "${file}", "-std=c++17", "-g", "-Wall", "-lm", "-o", "${fileDirname}/${fileBasenameNoExtension}.out" ], "group": "build", "presentation": { "reveal": "silent", "panel": "shared", "echo": true, "focus": false, "showReuseMessage": true, "clear": false }, "problemMatcher": "$gcc" }, { "label": "run c++", "type": "shell", "dependsOn": "build c++", "command": "${fileDirname}/${fileBasenameNoExtension}.out", "presentation": { "focus": true }, "group": "test" } ] }
该文件其实就是一个命令行构建工具。
把运行程序时在终端输入的命令和参数对于"command"和"args"的值
输入shift+command+b,即可构建成功,生成可执行文件「文件名」.outspa
[⇧⌘P]打开命令模式,选择[Debug: Open launch.json]命令,选择的模板为C/C++,回车后会自动在.vscode目录下生成一个launch.json文件,下面给出老哥的文件示例:.net
{ // 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": "c/c++ Launch", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "lldb", "preLaunchTask": "build c++", "logging": { "trace": true, "traceResponse": true, "engineLogging": true } } ] }
完成这三步C++开发环境就配置好了,接下来就能够编译,运行,调试C++程序了
[⇧⌘B]是编译程序,[⇧⌘R]是运行程序,若是安装了插件『Code Runner』能够直接运行程序
若是须要调试,那就按F5,进入调试模式便可插件
[⇧⌘B]会编译生成.out文件,再按[⇧⌘R]会在终端窗口显示运行结果 或者 进行交互。
参考文章
在mac上使用vscode建立第一个C++项目
Mac在VSCode中搭建C/C++环境命令行