在ubuntu7.10用终端编译运行c++程序

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script> 不用IDE工具,只用终端,测试->编译->运行,一气呵成!
具体步骤:
1,确保已经安装gcc,安装方法:sudo apt-get install gcc
2,编写一个简单的cpp文件test.cpp,放在指定地方
示例:
# include <iostream>
using namespace std;

int larger(int, int);
int main(){
int i, j;
cout<<"请输入两个数:"<<endl;
cin>>i>>j;
cout<<"较大的数是:"<<larger(i,j)<<endl;
}

int larger(int a,int b){
return a>=b?a:b;
}

将此程序保存在/home/user/桌面, 打开终端(注意user即你的系统用户名)
3, 编译: g++ /home/user/桌面/test.cpp -o test.out
4,如果没有提示错误,可以运行编译后的程序:./test.out

说明:test.out可以替换为任意的名字

你可能感兴趣的:(C++,c,C#,gcc,ide)