zoukankan      html  css  js  c++  java
  • fstream ifstream ofstream分块读写文件

     fstream ifstream ofstream分块读写文件

    #include <fstream>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        const int BUFFER_SIZE = 1024 * 10;
        std::ifstream ifs("e://setup_10.2.0.2001s.exe", ios::binary);
        std::ofstream ofs("e://setup_10.2.0.2001s2.exe", ios::binary);
        if (ifs) {
            ifs.seekg(0, ifs.end);
            int length = (int)ifs.tellg();
            ifs.seekg(0, ifs.beg);
            std::string buffer(BUFFER_SIZE, '');
            int offset = 0;
            int readSize = min(BUFFER_SIZE, length - offset);
            while (readSize > 0 && ifs.read(&buffer[0], readSize)) {
                ofs.write(&buffer[0], readSize);
                offset += readSize;
                readSize = min(BUFFER_SIZE, length - offset);
                std::cout << "offset:" << offset << std::endl;
            }
        }
        ifs.close();
        ofs.close();
    
        system("pause");
        return 0;
    }

     参考链接:fstream ifstream ofstream分块读写文件

  • 相关阅读:
    类型转换
    struts2默认拦截器
    struts2自定义拦截器
    struts2之I18N
    代理模式
    抽象类 abstract class 接口
    java基础题
    final
    内部类
    tomcat 端口占用问题解决
  • 原文地址:https://www.cnblogs.com/2018shawn/p/12307352.html
Copyright © 2011-2022 走看看