我不明白什么是写入文件file.write((char *) this, sizeof(BOOK)) ;
。请解释一下:)C++什么fstream写入函数写入文件(coden在后)
void add_new_book(int tcode,char tname[33], char tauthor[26], float tprice, int tcopies, int tavail)
{
fstream file ;
file.open("BOOK.DAT", ios::app) ;
bookcode = tcode ;
strcpy(name,tname) ;
strcpy(author,tauthor) ;
price = tprice ;
copies = tcopies ;
avail = tavail ;
file.write((char *) this, sizeof(BOOK)) ; }
您的代码不够完整,无法理解。请检查它是否编译并以某种方式运行后,请提供一个独立的示例。 –