zoukankan      html  css  js  c++  java
  • C++ 复制二进制文件

    这篇博客是对上一篇博客(C++ 文件二进制输入输出)的实践。主要目的是实现对二进制文件的复制。                                                                                                       

    源文件是一个叫“helloWorld.exe”的文件,在执行后,会打印一句“Hello World!”

    目标文件叫“test.exe”,由“helloWorld.exe”而来。

    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    
    
        ifstream fin("helloWorld.exe", ios::binary);
        ofstream fout("test.exe", ios::binary);
    
        bool bRet = true;
    
        while(!fin.eof()){
            char szBuf;
            fin.read(&szBuf, sizeof(char));
    
            if(fin.eof()) break;
    
            if (fout.bad())
            {
                bRet = false;
                break;
            }
            fout.write(&szBuf, sizeof(char));
        }
        
        fout.close();
        fin.close();
    
        return 0;
    }

    两个exe文件的运行结果:

     复制成功

  • 相关阅读:
    this指针详解
    C++处理异常
    C++中的this指针
    c++中的string类
    c面试题总结
    c++中的引用详解
    c++中的new和delete
    函数重载
    BST(二叉排序树)的插入与删除
    ccf行车路线
  • 原文地址:https://www.cnblogs.com/bwjblogs/p/12923779.html
Copyright © 2011-2022 走看看