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!"。

猜你喜欢

转载自www.cnblogs.com/2018shawn/p/9975136.html