我正在尝试这个DeleteFile()功能,我在下面编写了这个程序.
#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;
}
Run Code Online (Sandbox Code Playgroud)
但该计划没有按照预期的那样发挥作用.创建的文件未删除.
输出是:
fail
Run Code Online (Sandbox Code Playgroud)