Reading and writing binary file

前端 未结 7 593
挽巷
挽巷 2020-11-22 16:29

I\'m trying to write code to read a binary file into a buffer, then write the buffer to another file. I have the following code, but the buffer only stores a couple of ASCI

相关标签:
7条回答
  • 2020-11-22 17:02

    Here is a short example, the C++ way using rdbuf. I got this from the web. I can't find my original source on this:

    #include <fstream>
    #include <iostream>
    
    int main () 
    {
      std::ifstream f1 ("C:\\me.txt",std::fstream::binary);
    
      std::ofstream f2 ("C:\\me2.doc",std::fstream::trunc|std::fstream::binary);
    
      f2<<f1.rdbuf();
    
      return 0;
    }
    
    0 讨论(0)
提交回复
热议问题