Jump to content

  • Log In with Google      Sign In   
  • Create Account


Writing an item from a struct to a file

  • You cannot reply to this topic
1 reply to this topic

#1 haiphonghponline   Members   -  Reputation: 97

Like
-1Likes
Like

Posted 06 August 2014 - 06:42 PM

I need to write a specific item from a struct to a file that already exists and need to leave the rest of the data untouched.

Here is the code

void Game::SaveGameCompleted(const string &fileName)
{
ofstream out(fileName.c_str(), ios::binary);

if(!out)
return;

GameData gameData;

GetGameData(&gameData);

out.seekp(offsetof(GameData, GameCompleted), ios::beg);
out.write((char*)&gameData.GameCompleted, sizeof(gameData.GameCompleted));

out.close();
}

It seems to be causing a crash but I can't see any obvious reason why. 



Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 14980

Like
6Likes
Like

Posted 06 August 2014 - 07:45 PM

Required reading.





PARTNERS