Jump to content
  • Advertisement
Sign in to follow this  
back2newbelf

c++ and writing to files

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

hi i know how i open a file and write into it with ofstream but the problem is that information, that was stored in the file before, gets lost. is there a way to just add things into an existing file? thx

Share this post


Link to post
Share on other sites
Advertisement
Hey man..

There are multiple ways to do so..

Either you open the file for appending..

ofstream file ("filename", ios::out | ios::app);

or you might open it normally and then seek to the end:

file.seekg (0, ios::end);

Moreover, you can open a file with the read\write pointer directly pointing to the end of the file (without having to call gseek)

ofstream file ("filename", ios::out | ios::ate);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!