c++中文件的读写

//文件的读写
#include <fstream>
void wenjian1()//文件的打开,读取,关闭  ios::in 读取文件 ios::out 写文件 ios::app 写文件的时候不覆盖原文件
{
    char * filename="";
    char * filename1="";
    ifstream readfile(filename,ios::in);//读取文件时的打开方式方式1
//    ifstream readfile1;//读文件对象
//    readfile1.open(filename,ios::in);//读取文件时的打开方式2

    ofstream readfile_w(filename1,ios::out|ios::app);//写文件时的打开方式方式1
//    ofstream readfile_w1;
//    readfile_w1.write(filename,ios::out);//写文件时的打开方式方式2

    //判断文件打开是否成功
    if (!readfile)
    {
        cout<<"打开文件失败"<<endl;
    }
    //读文件
    char ch;
    while (readfile.get(ch))//将一个文件内容,另一个文件内
    {
        cout<<ch;//读取文件方式 .get()
        readfile_w.put(ch);//写入文件方式 .put()
    }
    //关闭文件
    readfile.close();
    readfile_w.close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值