So i have this binary file with some player's data written in it. I want to print the hole file, ( i have class player that contains some data) there is some data printed to the screen but after that an exception is thrown.
void Player::print_statistics()
{
ifstream file; string str; Player plyr;
file.open("player_database.dat", ios::binary);
while(file.read((char*)&plyr, sizeof(Player)))
{
file.read((char*)&plyr, sizeof(Player));
cout << plyr.full_name << " " << plyr.ingame_name << " " << plyr.age << " " << plyr.hours_played << "\n";
}
}
Exception thrown: read access violation. _Pnext was 0x148E2B4. occurred. I tried the following:
while(!file.eof())
doesn't work
while(file>> string)
doesn't work. This is the calss :
using namespace std;
class Player
{
protected:
string password;
int age = 0;
long int id_nmber=0 ;
string email, ingame_name, full_name;
public:
// ...
};