前言
文件IO
,又称系统IO
,系统调用
打开 open
流程:1.创建一个.c在vim中编译
2.引入头文件
#include<unistd.h> #include<fcntl.h> #include<errno.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h>
3.代码
int fd = open("3.txt",O_RDWR|O_CREAT,0777);
4.代码说明
设定返回值类型 一般打开是int型的
利用open打开(“文件名和文件类型”,O大写_方式(只读/只写/读写)|或O_CREAT没有创建,0xxx权限分配)
5.判定是否打开成功,要严谨
if(fd<0){ printf("qnmd\n"); printf("error no",errno); }else{ printf("succ %d\n",fd); }
读
就是从文件中读取数据
模式:O_RDONLY或者O_RDWR(只读模式/读写模式)