我正在尝试编写一个程序来保存链接列表的内容(每个单独的列表都称为局部性并包含多种数据类型)。代码编译但意外终止;它让我参考 ifstream 库中的行(即使我只想使用写作)
*_Str = _Elem(); // add terminating null character
有谁知道出了什么问题?
//saves a single locality onto a file
void fSave_locality(Clinked *current, fstream *fout)
{
fout->write(current->site_name,100);
fout->write((char*) ¤t->cood_x,sizeof(double));
fout->write((char*) ¤t->cood_y,sizeof(double));
fout->write((char *) ¤t->dip,sizeof(double));
fout->write((char *) ¤t->strike,sizeof(double));
if (current->next!=NULL) fSave_locality(current->next,fout);
}
void fSave_list(char* fname)
{
fstream *fout;
do
{
cout<<"Would you like to save as a (b)inary or (t)ext file? ";
test = getch();
cout<<"Enter file name (make sure its unique!): ";
cin.getline(fname,100);
if(toupper(test)=='T') fout->open(fname, fstream::out);
if(toupper(test)=='B') fout->open(fname, fstream::out| fstream::binary);
}
while(toupper(test)!='T' || toupper(test)!='B');
if(fout->fail())
{
cout<<"unable to open file.\n";
exit(0);
} //it gets to here without any problems.
current = start;
while(current->next!=NULL)
{
fSave_locality(current, fout);
current=current->next; //repeat for the next object in the list
}
fout->close();
}