Jump to content
  • Advertisement
Sign in to follow this  
back2newbelf

c++ and writing to files

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

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!