////
+/// Destructor. Be sure file is closed before we leave.
+
+Book::~Book() {
+
+ close();
+}
+
+
/// Book::open() opens a book file with a given file name
void Book::open(const string& fName) {
+ // Close old file before opening the new
+ close();
+
fileName = fName;
ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary);
if (!is_open())
if (!good())
{
cerr << "Failed to open book file " << fileName << endl;
- close();
exit(EXIT_FAILURE);
}
}
if (!good())
{
cerr << "Failed to read book entry at index " << idx << endl;
- close();
exit(EXIT_FAILURE);
}
}