← 返回首页
Linux高级程序设计(二十二)
发表时间:2021-11-11 22:52:49
remove函数

1.remove

remove函数用来删除一个文件。

#include <stdio.h>

int remove(const char *pathname);

实例:

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
//#include <unistd.h>
//windows下无法打开源文件"unistd.h"采用以下方式解决
#ifndef _UNISTD_H
#define _UNISTD_H
#include <io.h>
#include <process.h>
#endif

int main(int argc, char const *argv[])
{
    if(remove("./test.txt")==-1){
        perror("fail to remove file:");
        return -1;
    }

    printf("delete file success!");
    return 0;
}