How can I delete a file pointed to by a FILE* in C?

前端 未结 5 1568
予麋鹿
予麋鹿 2021-01-19 04:56
#include

int main() {

    FILE* fp;
    fp = fopen(\"temp.txt\", \"w\");
    fprintf(fp, \"Hello, World!\\n\");

    // remove(\"temp.txt\");  this          


        
5条回答
  •  Happy的楠姐
    2021-01-19 05:31

    I don't believe there's any way to do this, because a FILE* may not necessarily correspond to a file in the filesystem at all (For example, stdin and stdout).

    And in filesystems that support hard links, there can be multiple paths referring to the same underlying file, which one would you want it to remove?

提交回复
热议问题