For my school project, i am creating a game. For save game features, I am using a .DAT
binary file to read and write the data. When I enter the necessary details, the file doesn't have any data stored in it after exiting the program.
void save_game()
{
savegame sg;
fstream x("savegame.dat", ios::out|ios::binary);
char pn[25];
sg.points = point;
sg.lives = count;
clrscr();
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);
outtextxy(50, 50, "ENTER YOUR NAME,PLAYA!");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
gets(pn);
strcpy(sg.pname, pn);
x.write((char*)&sg, sizeof(sg));
quitgame();
}
When I open the .DAT
file, I expect to have some data stored in it. However, the file remains empty.