Linux下使用GCC编译并运行第一个helloworldC++程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Liekkas_Javey/article/details/52819227

第一步:只需要安装两个软件:
一个是编译器gcc,另一个是bild-essential(输入sudo apt install build-essential 即可)。

第二步:在终端输入subl hello.c(其中编辑器我使用的是Sublime Text 3)
输入下述代码然后保存至目录home下。

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout << "Hello World!" << endl;
    return 0;
}

第三步:编译hello.c ,并输出。命令如下:
这里写图片描述
如果要改变输出文件的名称,可以将终端第二行改为g++ hello.c -o hello.out(即生成名为hello.out的可执行文件),第三行改为./hello.out即可输出。

至此成功输出hello world,完成。

猜你喜欢

转载自blog.csdn.net/Liekkas_Javey/article/details/52819227