六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 11|回复: 0

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

[复制链接]

升级  32.6%

213

主题

213

主题

213

主题

进士

Rank: 4

积分
663
 楼主| 发表于 2013-2-4 20:01:53 | 显示全部楼层 |阅读模式
<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可以替换为任意的名字
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表