Delete the file specified by the user. - C++ File Stream

C++ examples for File Stream:File Operation

Description

Delete the file specified by the user.

Demo Code

#include <stdio.h>
#include <iostream>
using namespace std;
void main()/*from  w w w .  ja  v  a  2 s.c om*/
{
   char filename[12];
   cout << "What is the filename you want me to erase? ";
   cin >> filename;
   if (remove(filename) == -1)
   {
      cout << "\n*** I could not remove the file ***\n";
   }
   else
   {
      cout << "\nThe file " << filename << " is now removed\n";
   }
   return;
}

Result


Related Tutorials