read_write函数
1. read函数
- 函数原型: ssize_t read(int fd, void *buf, size_t count);
- 参数:
- fd:文件描述符,open函数的返回值
- buf:缓冲区,存储要读取的数据
- count:缓冲区能存取的最大字节数 sizeof(buf)
- 返回值:
- -1 :失败
- >0:读取的字节数
- =0:文件读完了
2. write函数
- 函数原型:ssize_t write(int fd, void *buf, size_t count);
- 参数:
- fd:文件描述符,open函数的返回值
- buf:缓冲区,要写到文件的数据
- count:能存取的有效字节数
- 返回值:
- -1:失败
- >0:写入到文件的字节数
- =0:读取结束
%%拷贝english.txt到一个新文件中
#include <stdio.h>
#include <unist.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <fcntl.h>
int main(int argc, const char*