在Visual Studio Code编写C语言/C++的代码和运行结果

方法一:

在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”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值