Hello,

I've created a file and put datat into it, only problem is that throughout the operation of the program the file is "amended" and bits are added to the file. However I'm wonder if theres a way to delete the file contents so next time someone starts the appilcation the contents of the file are no longer there?

Cheers

John

Recommended Answers

All 2 Replies

If I'm understanding you correctly, you want to append to the file while the program is running, but you want the file to be empty when you start the program the next time?

If I'm correct, just open the file in write mode, rather than append mode, in your program shutdown code and your program startup code (the startup portion is to handle cases when your program terminated improperly).

I think you mean 'appended'.
If you want to overwrite a file, you could just use the default

ofstream myFile("SomeFileName");

and that will truncate the information in the file.

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.