赞
踩
- %%拷贝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* argv[])
- {
- //打开一个文件
- int fd=open("english.txt",O_RDWR);//english.txt保存在main.c同一个文件夹
- printf("fd = %d\n", fd);
-
- //打开另一个文件,写操作
- int fd1 =open("temp.txt",O_WRONLY | O_CREAT, 0664);//若没有temp.txt文件,会new一个,权限为0664;
- printf("fd1 = %d\n", fd1);
-
- //从fd读取数据
- char* buf[4096];//设置4K个字节的缓冲区
- int len = read(fd,buf,sizeof(buf));
-
- while(len>0){
- //写入数据
- int ret = write(fd2,buf, len);
- printf("ret = %d\n",ret);
- //继续读取下一块的数据
- len = read(fd,buf,sizeof(buf));
- }
-
- close(fd);
- close(fd1);
- return 0;
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。