Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Writing an item from a struct to a file

4: Adsense

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   

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. 



#2 ApochPiQ   Moderators   

22536
Like
6Likes
Like

Posted 06 August 2014 - 07:45 PM

*
POPULAR

Required reading.
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]




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.