Sign in to follow this  

C++ binary file header/footer

This topic is 3496 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

This topic is 3496 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this