我正在使用visual studio 2013.我的项目是图书馆管理系统。读取我的文件后,它是访问voilation的例外。 0000005:在0x6534DF58(msvcp120d.dll)在第3扫描电镜决赛PROJECT.exe访问冲突读取位置0x012D363C
class Book {
string edition;
string serialno;
string shelfno;
int date, month, year;
public:
Book();
Book(char name, char aname, string edit, int srno, int shfno);
void getbook();
void showbook();
void getdate();
string bookname;
string authorname;
};
Book::Book()
{
bookname = "BOOKNAME";
authorname = "AUTHORNAME";
edition = "EDITION";
serialno = "SERIALNO.";
shelfno = "SHELFNO.";
}
void Book::showbook()
{
cout << bookname << " ---- " << authorname << " ---- " << edition << "---- " << serialno << "----" << shelfno << endl;
}
void Librarysystem::showrecord()
{
ifstream file;
Book b;
file.open("bookrecord.txt", ios::in);
if (!file)
cerr << "\n could not open file:";
cout << "\t\t BOOK RECORD\n\n" << endl;
while (!file.eof()) {
b.showbook();
file.read(reinterpret_cast<char*>(&b), sizeof(b));
if (file.eof())
file.close();
//cerr << "\n could not read from file:";
}
}
未处理的异常访问冲突读取位置0x012D363C。 这是例外
你不能反序列化这样的对象,如果它们不包含POD-唯一成员。你能告诉我们“Book”的定义吗? –
本书当然不是POD类型..从来没有保存对象的状态,保存它的字段值。你需要在课堂上的序列化方法 – Swift
请学会缩进你的代码;它可以帮助我们进行调试,它也可以帮助您*。 – cybermonkey