Book Administrator::bookDetails()
{
Book book;
list<Book> books;
string title;
string author;
int ISBN;
string userInput;
while (userInput != "q")
{
cout << "Would you like to enter a book?" << endl;
cin >> userInput;
if (userInput == "yes")
{
cout << "What is the title of the book you want to enter?" << endl;
cin >> title;
cout << "What is the author of the book you want to enter?" << endl;
cin >> author;
cout << "What is the ISBN of the book you want to enter?" << endl;
cin >> ISBN;
book.setTitle(title);
book.setAuthor(author);
book.setISBN(ISBN);
books.push_back(book);
}
list<Book>::iterator pos;
pos = books.begin();
for (pos = books.begin(); pos != books.end(); pos++)
{
//There error is produced here
cout << *pos << "\n";
}
}
return book;
}
Это функция bookDetails
моего класса администрирования. Он просматривает и запрашивает название книги, автора и номер ISBN, и когда он заканчивается, он подталкивает книгу к списку.
Кажется, это нормально работает, когда я отлаживаю его, но я получаю сообщение об ошибке, когда пытаюсь распечатать детали каждой книги, используя итератор.
Может кто-нибудь помочь мне здесь? благодаря
Вам необходимо реализовать operator<<
для Book
std::ostream operator<<(std::ostream& os, const Book& book)
{
os << book.title << " " << book.author; // print out other information
return os;
}