1. 程式人生 > >Ubuntu下編輯並編譯執行c++程式

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