65,186
社区成员




template<class T,class T1>
void File<T,T1>::Append(char*fn1,char*fn2,T1 e)
{
ofstream ofs(fn1,ios::out|ios::binary);
if(!ofs){cout<<fn1<<"不能打开"<<endl;exit(1);}
ofs.seekp(0,ios::end);
int flen=ofs.tellp()/b1; //当前文件个数
ofs.write((char*)& e,sizeof(e));
ofs.close();
T x;
strcpy(x.key,e.key);
x.length=0;
x.location=0;
IFInsert(fn2,x);
cout<<"添加记录完成\n";
}
template<class T,class T1>
void File<T,T1>::IFInsert(char*fn2,T x)
{
fstream ifs(fn2,ios::in|ios::binary);
if(!ifs){cout<<fn2<<"不能打开"<<endl;exit(1);}
……
}
void main()
{ char *p1=".\\File.dat",*p2=".\\File.idx";
……
File<IndexItem,ElemType>myfile;
myfile.Append(p1,p2,e);
}