c++ fstream用法


今天介绍一个复制 粘贴的函数,用fstream实现

#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    fstream in("a.jpg", ios_base::binary|ios_base::in);
    if (in.is_open())
    {
        fstream out("F:/1/nature.jpg", ios_base::binary|ios_base::out);
        if (out.is_open())
        {
            char* buf = new char[255];
            while (in.good())
            {
                in.read(buf, 255);
                int count = in.gcount();
                out.write(buf, count);
            }
            out.close();
        }
        in.close();
    }
    return 0;
}

 

示例展示:

原来的文件:

 

运行程序后:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM