void Admin::AddGame(Games& g, int id) { Games empty; fstream to_handle("Games.dat", ios_base::in | ios_base::out | ios::binary); if (!to_handle.is_open()) { cout << "Could not open file, press any key to exit:" << endl; fflush(stdin); getchar(); exit(1); } to_handle.seekg((id - 1)*sizeof(Games)); to_handle.read(reinterpret_cast<char*>(&empty), sizeof(Games)); string Void = empty.getName(); if (Void == "") { to_handle.seekp((id - 1)*sizeof(Games)); to_handle.write(reinterpret_cast<const char*>(&g), sizeof(Games)); cout << "Data has been written!" << endl; } else { cout << "Block no.#" << id << " is not empty" << endl; } to_handle.close(); }
void Admin::SeeAllGames() { Games blank; int c = 1; string Void; fstream to_handle("Games.dat", ios_base::in|ios_base::out|ios::binary); if (!to_handle) { cout << "Could not open file, press any key to exit:" << endl; fflush(stdin); getchar(); exit(1); } to_handle.seekg(0, ios::beg); while (to_handle.read(reinterpret_cast<char*>(&blank), sizeof(Games))) { Void = blank.getName(); if (Void!= "") { cout << blank; blank.Display(); cout << "at ID: " << c << endl; } c++; } to_handle.close(); }