1、write和read方法讲解
#include<unistd.h>
ssize_t read(int fd, void *buf,size_t count);
fd为文件描述符,buf缓冲区指针,count表示要读取的字节数
返回:读到的字节数,若已经到文件尾端返回0,出错返回-1
#include<unistd.h>
ssize_t write (int fd, void *buf, size_t count);
fd为文件描述符,buf缓冲区指针,count表示要写的字节数
返回:若成功已写的字节数,若出错为-1
2、代码实现读写
比如在/home/chenyu/Downloads/chenyu文件进行写和读
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<fcntl.h>
//特么你这里要注意了,不需要写=号,字符串记得加双引号
#define FILEPA
最后
以上就是淡淡外套最近收集整理的关于linux c通过文件描述符以及write和read方法对文件进行读写的全部内容,更多相关linux内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复