1. 程式人生 > 其它 >Ubuntu執行C++程式

Ubuntu執行C++程式

技術標籤:c++相關

1 使用touch helloworld.cpp建立一個名為helloworld的c++檔案

2 用ls檢視建立檔案是否存在

3 用vi helloworld.cpp開啟檔案進行編輯,保持

#include<iostream>
using namespace std;

int main(){

    cout<<"hello world"<<endl;
    return 0;
}

4 用g++ helloworld.cpp -o helloworld執行該程式,結果儲存在helloworld檔案中

5 用./helloworld檢視執行結果

ps:Linux下編譯C語言用的是gcc命令,而編譯C++程式則用的是g++命令, 要特別注意