编译环境Visual Studio Coder in Ubuntu
文件头:
#include <fcntl.h>
#include <unistd.h>
需要了解打开文件时不同权限的意思:
1) O_CREAT:表示如果文件不存在,便会创建新文件
2) O_APPEND:表示添加
3) O_RDWR:表示可读可写
4) S_IRUSR:所有者拥有读权限
5)S_IWUSR:所有者拥有写权限
6)O_RDONLY:打开的文件只可读
7)O_WRONLY:打开的文件只可写
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
int fd;
fd = open("Angela_test.txt", O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR);
write(fd,"Hello",strlen("Hello"));
close(fd);
return 0;
}
编译结果: