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;
}

示例展示:

原来的文件:

运行程序后:

猜你喜欢

转载自www.cnblogs.com/Trojan00/p/9066622.html