Link to home
Start Free TrialLog in
Avatar of shaolinfunk
shaolinfunkFlag for United States of America

asked on

How do I delete a file?

Ok, every time I run my little application it leaves behind a text file called C:\debug.txt.

I would like my app to delete this.  

What command/code do I need to use in VC++ to delete this file?  

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phoffric
phoffric

For full path, you may need \\ as in:
remove("c:\\debug.txt");

Open in new window

Oh, I forgot to mention that you should close your file before deleting it.
Avatar of shaolinfunk

ASKER

Works like a charm.  Thanks phoffric!
You didn't mention how you open and close, but in case you need this, here is sample code from:
     http://www.cplusplus.com/reference/iostream/ofstream/close/
     // ofstream::open
#include <fstream>
using namespace std;

int main () {

  ofstream outfile;

  outfile.open ("test.txt", ofstream::out | ofstream::app);
  outfile << "This sentence is appended to the file content\n";
  outfile.close();

  return 0;
}

Open in new window

Anytime. :)
yes, thank you for that additional info...i closed the file by using:

outfile.close();