I was trying the DeleteFile()
function, and I wrote the program below.
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main(){
FILE * filetxt;
// creat a file
filetxt = fopen("C:\\Users\\Thomas\\Desktop\\filetxt.txt", "w");
// delete the file
if (DeleteFile("\\\\.\\C:\\Users\\Thomas\\Desktop\\filetxt.txt") != 0){
cout<<"success";
}else{
cout<<"fail";
}
cin;
}
But the program didn't work as it was supposed to. The file created wasn't deleted.
The output is:
fail