PDA

View Full Version : Whats the most C++'esque way of emptying a file?



Bodsda
May 31st, 2009, 07:19 PM
Hi, I need to either remove all data from a file, or just delete the file. Whats the best way of going about this?

I'd prefer not to use rm -f via a system call

Regards,

Bodsda

Linteg
May 31st, 2009, 07:28 PM
http://www.cplusplus.com/reference/clibrary/cstdio/remove/

Bodsda
May 31st, 2009, 08:33 PM
oh, brilliant, just what I needed, thanks dude :)

Thanks,

Bodsda

soltanis
June 1st, 2009, 12:40 AM
Truncating the file to 0 also works if you plan on writing something else to it.

Opening the file in "write" mode automatically does this.