file i/o nightmare using fstream

Hi there! I've been trying to implement a database for a game I'm making, and I have a big problem.

My database has for content player profiles, which are appended to it has the game go along... the first two bytes in the database represent the number of profiles, and I'd like to update this number as the number of profiles increases.

I noticed that the only way to append content to a file without crushing it is to use the ios::app flag when opening the file... the problem is that when using ios::app, all output content is written at the end of the file... I've tried to write content at the beginning, but seekp(0, ios::beg) gets you to the end of the file, and tellp() gives a value of 0 there, even if it's at the end. I've tried putting a negative value if seekp(), to "go back" in the file, without success.

Does one of you guys have any idea how you can "change" the content of a file when it already has content?

Thanks,
AeonFlux1212
You have to read the contents of the entire file, then make the changes to those contents in memory, then overwrite the file with the edited contents.

Clunky, I know.
Yeah that's what I just figured.... I'll do that.

Thanks!
AeonFlux1212
Topic archived. No new replies allowed.