template<typename T>
T * save(T *p)
{
T *p1,*p2;
T *temp=NULL;
ofstream outfile("File.dat",ios::out|ios::binary);
if(!outfile)
{
cerr<<"Open file.dat error!"<<endl;
exit(1);
}
p1=p;
//p1->display();
//p2=p1;
//p1=p2->next;
//p1->display();
//p1=p;
while(p1!=NULL)
{
p2=p1;
//p1->display();
outfile.write((char *)p1,sizeof(T));
p1=p2->next;
}
outfile.close();
cout<<"Save successful!"<<endl;
return(temp);
}
template<typename T>
void load(T * p)
{
T * head,*p1=NULL,*p2;
if(p=NULL)
{
ifstream infile("File.dat",ios::in|ios::binary);
if(!infile)
{
cerr<<"Open error!"<<endl;
exit(1);
}
infile.read((char *)p1,sizeof(T));
p1->display();
head=p1;
while(p1->next!=NULL)
{
p2=p1;
infile.read((char *)p1,sizeof(T));
p1=p2->next;
}
infile.close();
}
cout<<"Load successful!"<<endl<<endl;
cout<<"*********Now diaplay*********"<<endl;
p1=head;
p1->display();
while(p1->next!=NULL)
{
p2=p1;
p1->display();
p1=p2->next;
}
}
save函数的参数是从一个动态链表返回来的head,save函数返回一个temp主要是为了load函数可以知道数据类型而已,不用理它
现在想请问各位,我的程序读不出数据,哪里出问题了???