Deleting or Renaming a File - C++ File Stream

C++ examples for File Stream:File Operation

Description

Deleting or Renaming a File

Demo Code

#include <iostream>
#include <cstdio>
#include <cerrno>

using namespace std;

int main(int argc, char** argv) {
   if (remove("main.cpp") == -1) {  // remove() returns -1 on error
      cerr << "Error: " << strerror(errno) << endl;
      return(EXIT_FAILURE);
   }/*ww w  .j a va 2s .c  om*/
   else {
      cout << "File '" << argv[1] << "' removed." << endl;
   }
}

Result


Related Tutorials