方法一:
在Visual Studio Code里,选择左边的一个图标(四个方块和时钟,Extensions),输入“C C++”,搜索一下,选择“C/C++”,按一下“Install”,输入“code runner”,选择“Code Runner”,按一下“Install”。在终端输入命令行:“clang --version”。
结果如下:
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
如果没有安装slang,输入命令行:“xcode-select --install”
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
选一个文件夹,拖到VScode,新建文件,输入文件名,后面带有C语语后缀格式。创建了Hello World.C ,输入代码行如下:
#include <stdio.h>
int main(){
printf("Hello World\n");
return 0;
}
右上角有三角形样子,直接运行即可。
新建文件,输入文件名,创建helloWorld.cpp,输入代码如下:
#include <iostream>
int main(){
std::cout<<"Hello World!"<<std::endl;
return 0;
}
右上角有三角形样子,直接运行即可。
第二方法:
菜单有Terminal--configure Default Build Task...
选择“C/C++:Clang++ build active file”