天天看點

Ubuntu下運作C/C++程式

​​https://www.linuxidc.com/Linux/2014-05/101844.htm​​​ ​

1.準備工作

1.1 打開控制台:使用快捷鍵 Ctrl + Alt + T;

1.2 安裝vim:輸入 sudo apt-get install vim;

1.3 安裝gcc:輸入 sudo apt-get install g++。

2.編寫hello.c源代碼

2.1 建立檔案名為hello.c的源檔案:輸入vim hello.c;

2.2 鍵入i 進入insert模式(即編輯輸入模式),寫入如下經典代碼:

//the first program hello.c
#include<stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}      

2.3 輸入完成後,Esc 回到normal模式,鍵入:wq 儲存退出vim。

3.編譯hello.c

在終端執行 g++ hello.c -o hello 編譯。

4.運作程式hello

./hello 就看到結果:

vim hello.cpp
g++ -o hellocpp hello.cpp
./hellocpp

然後就輸出了結果。。。
888      

繼續閱讀