hi, im having trouble when outputing the data from my program. i am trying to output numerous amounts of data into 1 txt file when running through a loop, but everytime it writes to my file it overwrites the previous data stored with in it. Can anyone offer some advice to stop this from happening? I am using the '.write' to output to my file.


thanks

Recommended Answers

All 3 Replies

hi sorry to double post, ive fixed it "ish". I have used , ios::app to append to my text file, however is there a way to break the file up by placing an empty line every time my program writes to the file so its more spaced out?


thanks and sorry again for double post

>everytime it writes to my file it overwrites the previous data stored with in it
It sounds like you keep closing and opening the file with the ios::out mode. In write mode, the newly opened file is truncated to zero length. You can avoid that by using ios::app (as you discovered), though that effectively means you can only write to the end of the file. Another alternative is ios::in | ios::out, which doesn't truncate the file and still allows you to seek.

>is there a way to break the file up by placing an empty line
>every time my program writes to the file so its more spaced out?
Why not just do out.put ( '\n' ); after you open the file but before you write any data?

Thank you very much that was exactly what i was after

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.