ubuntu编译运行c/c++代码(g++)

Ubuntu version is 14.04, with default g++ compiler.

Steps:

  1. 打开控制台,输入touch helloworld.c(pp),生成源代码文件。
  2. gedit helloworld.c(pp),使用gedit打开编辑源代码。
    比如:
    1
    2
    3
    4
    5
    6


    int (){
    printf("hello world!n");
    return 0;
    }

OR

1
2
3
4
5
6
#include <iostream>
using namespace std;

int (){
cout<<"Hello World!"<<endl;
}

  1. 编辑完成后保存退出,在控制台输入

    1
    g++ helloworld.c(pp) -o helloworld
  2. 通过./helloworld运行编译链接好的程序。