#include<stdio.h>
int main() {
FILE* fp;
fp = fopen("temp.txt", "w");
fprintf(fp, "Hello, World!\n");
// remove("temp.txt"); this requires the filename as an argument
// removefile(fp); <--- is something like this possible?
return 0;
}
删除函数 ( defined in stdio.h ) 将文件名作为参数,而不是文件指针本身。
C标准库中有没有删除文件,并以文件指针为参数的函数?
最佳答案
我认为没有任何方法可以做到这一点,因为 FILE* 可能根本不一定对应于文件系统中的文件(例如,stdin 和 stdout)。
在支持硬链接(hard link)的文件系统中,可以有多个路径引用同一个底层文件,您希望它删除哪一个?
关于c - 如何删除 C 中 FILE* 指向的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3657886/