一、终端输入
-
安装command line tools
xcode-select --install
这里是已经下载了
-
如果没有下载点击安装,等待安装完成即可
检验是否安装成功,终端输入
clang
如图所示是代表之前的command line tools安装 是安装成功的(Clang会不断更新的,更新位置系统更新中更新)
二、下载VSCode
Download Visual Studio Code - Mac, Linux, Windows
-
官网下载VSCode,下载对应的系统版本
-
解压的软件拖至应用程序
三、配置VSCode
-
打开VSCode提醒安装语言包,点击安装并重启
-
下载扩展,如图所示
-
搜索框中输入“C”,选择第一个扩展安装,第二个也可以安装(自选安装)
-
输入'runner',下载Code Runner
-
配置 Cod Runner
-
勾选第一个Clear Previous Output
-
勾选Ignor Selection
-
取消勾选Preserve Focus
-
勾选Run In Terminal
-
勾选Save All File Before Run
-
勾选Save File Before Run
四、完成配置
五、创建配置C,C++
1、创建一个文件夹
(自定义创建位置,只要自己能记住安装位置即可)
2、打开创建的文件夹
3、新建文件
文件后缀为.c是C文件,.cpp是C++文件
-
c文件
#include<stdio.h>
int main()
{printf("Hello World\n");return 0;
}
-
c++文件
#include <iostream>
using namespace std;
int main()
{cout<<"Hello World!"<<endl;return 0;
}
4、打开设置,将Auto Save修改成afterDelay
5、修改运行按钮
6、设置搜索栏搜索,并取消勾选
Debug Shortcut
7、 运行cpp文件,显示运行结果
-
C文件如下
8、调试配置
-
command+shift+p打开搜索框输入task,并打开
-
C语言选择clang,C++选择clang++
-
dask.json中配置c和c++
-
task.json文件所有的配置信息
(可直接复制,省事)
{"version": "2.0.0","tasks": [{"type": "cppbuild","label": "C/C++: clang 生成活动文件","command": "/usr/bin/clang","args": ["-fcolor-diagnostics","-fansi-escape-codes","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": "build","detail": "编译器: /usr/bin/clang"},{"type": "cppbuild","label": "C/C++: clang++ 生成活动文件","command": "/usr/bin/clang++","args": ["-fcolor-diagnostics","-fansi-escape-codes","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirna me}"},"problemMatcher": ["$gcc"],"group": "build","detail": "编译器: /usr/bin/clang++"}]
}
-
选择创建launch.json文件
-
点击添加配置launch.json文件所有的配置信息
{"version": "0.2.0","configurations": [{"name": "C调试","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": true,"MIMode": "lldb","preLaunchTask": "C/C++: clang 生成活动文件"},{"name": "C++调试","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": true,"MIMode": "lldb","postDebugTask": "C/C++: clang++ 生成活动文件"}]
}
-
点击调试输出结果如图所示
-
切换需要调试的类型