Jump to content
  • Advertisement
Sign in to follow this  

C++ binary file header/footer

This topic is 3804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm developing a program that interacts with a little database, using fstreams. Originally, I wrote it such that it maintained a header with file pointers to the various data members in the file. To do this, I wrote a full header full of dummy values first, then jumped back to each header entry as I wrote out the data members and knew their locations. When the program loads it reads this header, then displays a list of data members for the user. When the user clicks on one i can open the file and jump immediately to that data member in the file. The problem arises that I need to have variable length strings included in the header. I guess I could increment the file pointers as I add the strings, but I thought that perhaps instead I could just use a footer. I'd write all the data members first, then store the location immediately after the last data member byte. Then I'd write out my footer, identical what the header was but with the strings. The last byte then I'd write that location I stored. So when the program loads it would open the file with std::ios::ate, then rewind one byte ( seekg (1, ios::end)? ), read the footer location, etc. Is that a good solution, or is there a better way? Is it significantly different to read the last byte of the file first, etc?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!