file i/o, struct questions
I'm writing a battleships type game. Each player is represented as a struct, which contains 2 10 x 10 arrays, player's name, etc.
There are 2 players, but there are 4 instances of player, so that I can swap players, called p1, p2, current & opponent.
I want to be able to save the game, so I've created another struct, which contains 4 instances of player, called saveGame.
here's the save function:
I have a restore function which is similar, only in reverse.
save.savep1 = p1;
save.savep2 = p2;
save.saveCurr = current;
save.saveOpp = opponent;
ofstream outputStream("saveBattle.dat", ios::out | ios::binary);
cout << "Failed to open file";
outputStream.write((char *) &save, sizeof(saveGame));
cout << "Game has been saved";
So I have a struct that contains structs.
I then write that struct to a file, and read it to restore the game, using a similar process.
What I want to know is do I have to specifically use a loop process, to put the data back into the 10 x 10 matrices, for each player? Ive tried just using the call
ans so on for each player, and then continuing the game, but it doesn't seem to work.
p1 = restore.savep1;
Sorry if what I have written isn't clear. It's quite hard to explain!
Thanks in advance,