Ubuntu下编辑并编译运行c++程序

一、使用vim编辑c++代码:

vim hello.cpp

输入如下代码:

#include <iostream>
using namespace std;
int main()
{
    cout<<"Hello world!"<<endl;
    return 0;
}

二、编译代码:

gcc hello.cpp -lstdc++ -o hello

g++ hello.cpp -o hello

三、运行

./hello

注意:这里是输入"./hello"而不是hello。

然后你就能看到屏幕上输出了一个"Hello world!"。

 

posted @ 2018-11-17 18:57  余生以学  阅读(6568)  评论(0编辑  收藏  举报