linux----read读取文件并用write写入到新文件

本文介绍了如何在Linux环境中使用C++编程语言读取指定文件的内容,并将这些内容写入到一个新的文件中。通过示例代码详细展示了read和write系统调用的使用方法。
摘要由CSDN通过智能技术生成
  1 /*************************************************************************
  2     > File Name: MyOpen.cpp
  3     > Author: xuchen_allen
  4     > Mail: xuchen_allen@163.com 
  5     > Created Time: 2019年01月29日 星期二 10时11分33秒
  6  ************************************************************************/
  7 
  8 #include<iostream>
  9 using namespace std;
 10 #include<sys/types.h>
 11 #include<sys/stat.h>
 12 #include<fcntl.h>
 13 #include<unistd.h>
 14 
 15 int main()
 16 {
 17     //打开一个已经存在的文件
 18     int fd = open("english.txt",O_RDWR);
 19     if(fd == -1){
 20         perror("open file:");
 21         exit(1);
 22     }
 23 
 24     //创建一个新文件,在其中写入读取的内容:
 25     int fd_1=open("newfile",O_CREAT | O_WRONLY,0664);
 26     if(fd_1 == -1){
 27         perror("write:");
 28         exit(1);
 29     }
 30 
 31     //读取文件内容&#x
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值