So yeah, I have asked about this before, this time I manage to create a save file, load the setting of the game but some how I am struggling with loadding the player information.
I think the problem is in how I put the variable player[] in the function but I do not know how to fix it.
I will only post the struct and the function because it's where the problem lies.
right away I spot that you loop over playerturn to write into the file, but you did NOT WRITE playerturn's data into the file, so the reader has NO CLUE how many loops were written. You need to write it into the file before the loop, then you can read it and refer to its value to loop and read the array data.
-> it is OK for the other loop which is always 2 iterations.
The value of playerturn used for save must be the same value as used for load. As you don't save this value when save and hence aren't reading it from the file, you need to pass the required value to load.
What's the difference between playerturn and turn? Perhaps these changes (not tried):
If L19 is:
void savegame(int playerturn)
then L32
file << playerturn << endl;
L50 becomes:
int loadgame(int &playerturn, player_information player[3])