• 安装C/C++编译器

在终端下执行指令  sudo apt-get install build-essential

  • 编译第一个C程序

创建文件first.c

1 #include <stdio.h>
2 
3 int main(){
4    printf("hello,world\n");
5    return 0;      
6 }

执行下面命令编译

cc -c first.c

然后创建一个执行文件

cc -o first first.c

现在可以运行下面命令

./first

得到结果

hello,world

  • 编译第一个C++程序

创建文件first.cpp

1 #include <iostream>
2 
3 int main(){
4    std::cout << "hello world" << std::endl;
5    return 0;
6 }

执行下面命令来运行文件

g++ first.cpp -o test

./test

输出结果如下

hello world

posted on 2013-06-17 23:46  niusixiong  阅读(297)  评论(0)    收藏  举报