标签:
creat:
创建文件,显然参数只需要(路径path,权限mode)。
1、如果文件存在怎么办?直接覆盖掉!不管你里面有没有内容。
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include<iostream>
using namespace std;
int main()
{
        int fd;
        //umask(0000);
        fd=creat("grb.txt",0777);
        if(fd==0)
                cout<<"create failed!\n";
        else
                cout<<"create successful!\n";
}
创建成功,但是有个问题。
给的权限八进制777最大权限,但是查看权限的并不是。
 
#include<stdio.h>
#include <unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
        umask(0000);
        int fd=open("guo0.txt",O_EXCL|O_CREAT,0777);//新建一个文件,并给予最大权限,若存在则报错。
        if(fd==-1)
        {
                printf("creat failed!\n");
        }
        else
        {
                printf("creat successful!\n");
        }
        close(fd);
        return 0;
}

标签:
原文地址:http://www.cnblogs.com/grb2015/p/5557053.html