读书人

程序结果生成记事本的有关问题?

发布时间: 2012-04-06 12:22:24 作者: rapoo

程序结果生成记事本的问题????
#include <iostream>
#include <fstream>
using namespace std;
int base[10]={0};//
int t[2]={0};
void input(int *base,int &k)
{
int i,j,temp;k=0;
cout < < "请输入这八组数 " < <endl;
for(i=0;i <10;i++)//
{
cin> > temp;
for(j=0;j <i;j++)if(base[j]==temp)break;
if(i==j)base[k++]=temp;
}
if(k <2)exit(1);//数据不满足要求,直接退出;
cout < < "这八组中不重复的数有 " < <endl;
for(i=0;i <k;i++)cout < <base[i] < < " ";
cout < <endl < <endl;
}

void make(int *base,int k,int co,int pos)
{
ofstream outfile( "fangan.txt ", ios_base::out);
if (!outfile)
{
cerr < < "error: can not open \ "fangan.txt\ " for output\n ";
exit(-1);
}
if(co==2)//够了. 输出. co=2 k=10


{
for(int i=0;i <2;i++)cout < <t[i] < < " ";
cout < <t[0]*t[1];
outfile < <t[0]*t[1];

cout < <endl;
return;
}
if(pos==k)return;//没了.
make(base,k,co,pos+1);
t[co++]=base[pos];//改变当前
make(base,k,co,pos+1);

}

int main()
{
int k,co=0,pos=0;
input(base,k);
make(base,k,co,pos);
system( "PAUSE ");
return 0;
}
比如输入: 0,1,2,3,4,5,6,7,8,9 输出的结果应该有45行
把结果生成到记事本
outfile < <t[0]*t[1];
但记事本结果只用一行
大家帮我看下哪的问题.......

[解决办法]
ofstream outfile( "fangan.txt ", ios_base::out|ios_base::app); //app追加模式

读书人网 >C++

热点推荐