#include<iostream>
#include<fstream>
#include<vector>
class Book
{
public:
Book();
Book(std::string set_book_name, std::string set_ISBN, bool set_check);
Book(const char* set_book_name, const char* set_ISBN, bool set_check);
Book(const Book& one);
private:
std::string book_name;
std::string ISBN;
bool check;
};
class User
{
public:
User();
private:
void read_in_data(void);
std::vector<Book> list;
};
Book::Book() :book_name(""), ISBN(""), check(true)
{
}
Book::Book(const char* set_book_name, const char* set_ISBN, bool set_check) : book_name(set_book_name), ISBN(set_ISBN), check(set_check)
{
}
Book::Book(const Book& one)
{
book_name = one.book_name;
ISBN = one.ISBN;
check = one.check;
}
User::User()
{
read_in_data();
}
void User::read_in_data(void)
{
std::ifstream ins;
ins.open("data.dat");
if (ins.fail())
{
std::cout << "File data.dat can't be read.\n";
exit(1);
}
Book temp;
while (ins.read(reinterpret_cast<char *>(&temp), sizeof(Book)))
{
list.push_back(temp);
}
ins.close();
return; }
int main()
{
User user; return 0;
}
What I have tried:
My programming steps is:
First:I note line::90,then execute this program to write data to file data.dat.
Second:I note line::75 to line::89,then execute program to read data from data.dat to object User::user,at this time,memory error was given.
By the way,My English grammer is bad,I hope you can try to understand my intention,I really need your help.