Jump to content

  • Log In with Google      Sign In   
  • Create Account

Writing an item from a struct to a file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • 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: 15698

Like
6Likes
Like

Posted 06 August 2014 - 07:45 PM

Required reading.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS