Then you are asking to do something system-dependent... What platform are you on?
nearlyanexpert
ASKER
Windows...sorry, I wasn't aware it would make a difference :)
posternb
There is a Windows function DeleteFile, which takes a filename as a parameter and returns a BOOL (I believe) indicating success. Check it out on msdn for more details, there is also a whole slew of other functions to copy, move, etc...
Noooo... :) I'm not wanting to delete the file, I'm wanting to clear it, as jhance said I can use:
1) Open the file for READ.
2) Read the stuff you want.
3) Close the file.
4) Open the file for WRITE.
5) Close it.
But I've got over 3k files, which will grow by large amounts, so I'm wanting a less file opening and closing as possible. I want to read the file in and I then want to clear the files contents.
NAE
posternb
Oops, I'm sorry I forgot -- duh. Try CreateFile() instead then. You can set the CREATE_ALWAYS flag to overwrite existing files though I wonder if this has any performance gain over open/closing the file...
Your could try using conio.h. After the line you put insert:
dude1337
Your could try using conio.h and iostream.h. After the line you put insert:
cout.flush();
getch();
That will pause it until you press any key. Then put this in to clear it.
clrscr();
jhance
There is NO getting around opening and closing. Sorry, but if you have designed a silly application that uses 3000 files, then you have only yourself to blame....
If you don't want to open each file 2X, I suppose you could OPEN, READ, CLOSE, DELETE, and then COPY a BLANK file to same name as the one you just deleted.
Jhance, "Sorry, but if you have designed a silly application that uses 3000 files, then you have only yourself to blame...."
I wish it was a silly application! Unfortunately its massive, and this part of the program doesn't even touch the main application I've already got :) Each text file is already over 400k big, and as I've said, not only will that grow but the number of files will also! I just wondered if there was a way to clear a file without actually opening and closing it, but as there doesn't seem to be, I'll be a good sport and just accept the first comment that I would have done anyways :)
Thanks everybody for your response, congrats Jhance, another A...
Dude1337, keep trying...as Jhance said, your answer just didn't relate at all to what I wanted :)
netfileio.open("C:\\dir1\\
if you open a file for output and don't specify append mode it is immediately overwritten.