今天介绍一个复制 粘贴的函数,用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;
}

 

示例展示:

原来的文件:

c++ fstream用法

 

运行程序后:

c++ fstream用法

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2022-12-23
  • 2021-06-07
  • 2022-02-26
  • 2021-06-20
相关资源
相似解决方案