zoukankan      html  css  js  c++  java
  • C++ stl 复制文件的方法

    头文件
    #ifndef ioshelperH
    #define ioshelperH

    #include <fstream>
    #include <vcl.h>
    //---------------------------------------------------------------------------

    class IOHelper
    {
    public:
    void CopyFiles(char* srcPath, char* destPath);
    };
    #endif
    ======================================================
    源码
    void IOHelper::CopyFiles(char* srcPath, char* destPath)
    {
    //using namespace std;
    ifstream src(srcPath, ios::binary | ios::in);
    if (src.fail()) {
      //"file src does not exist"
      return;
    }
    ofstream dest(destPath, ios::out | ios::binary | ios::app);

    char buffer[32767];

    //获取文件大小
    //int filesize;
    //src.seekg(ios::beg, ios::end);
    //filesize = src.tellg();

    src.seekg(ios::beg);
    dest.seekp(0);

    while (src.good())
    {
      memset(buffer, 0, sizeof(char) * 32767);
      src.read(buffer, 32767);

      dest.write(buffer, src.gcount());

      if (src.gcount() < 32767)
                break;
    }
    }

  • 相关阅读:
    cf 785#
    hdu 4920 Matrix multiplication
    poj 2443 Set Operation
    bzoj 3687: 简单题
    洛谷 三月月赛 C
    洛谷 三月月赛 B
    洛谷 三月月赛 A
    bzoj 3156: 防御准备
    bzoj 3437: 小P的牧场
    bzoj 3675: [Apio2014]序列分割
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1332916.html
Copyright © 2011-2022 走看看