입니다. Visual Studio 2013을 사용하고 있습니다. 내 프로젝트는 라이브러리 관리 시스템입니다. 내 파일을 읽을 때 액세스 위반은 예외입니다. 가 0xc0000005 : 3 학기 최종 PROJECT.exe에서 0x6534DF58 (msvcp120d.dll)에서액세스 위반 읽기 위치는 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을 읽고. 이 예외
당신이 그와 같은 객체를 직렬화 할 수 없습니다 (예를 들어
operator<<
및operator>>
를 재정 의하여)Book
에 적절한 & 특정 직렬화/역 직렬화 메소드를 작성하는 것입니다. 'Book'의 정의를 보여줄 수 있습니까? –확실히 POD 타입이 아닙니다. objec의 상태를 절대로 저장하지 않고 필드 값을 저장합니다. 클래스 – Swift
내부에 직렬화 메서드가 필요합니다. 코드를 들여 쓰기를 배우십시오. 디버깅에 도움이되며 도움이됩니다. – cybermonkey