write to file multiple times

hello,
I have a problem with writing to the same file in seperate cases.

I opened a file
1
2
3
ofstream myfileRandom("random.log");
    if(myfileRandom.is_open())
    	myfileRandom.close();


and after some code , I wrote to the file:
1
2
3
myfileRandom.open("random.log");
myfileRandom <<""bla bla<<endl;
myfileRandom.close();


every time I write to the file it deletes my previous data.
how can I write to file without deleting previous data?

Thnx alot!
myfileRandom.open("random.log", ios::ate);
what peter said, or don't close the file until the end of your program.

ios::app -- Append to the file
ios::ate -- Set the current position to the end
ios::trunc -- Delete everything in the file
Last edited on
http://www.cplusplus.com/doc/tutorial/files/

scroll down till you reach
get and put stream pointers
Thank you guys! works now
Topic archived. No new replies allowed.