Advertisement
losmi93

C++ print file

Dec 16th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. // Copy a file
  2. #include <fstream>      // std::ifstream, std::ofstream
  3.  
  4. int main () {
  5.   std::ifstream infile ("test.txt",std::ifstream::binary);
  6.   std::ofstream outfile ("new.txt",std::ofstream::binary);
  7.  
  8.   // get size of file
  9.   infile.seekg (0,infile.end);
  10.   long size = infile.tellg();
  11.   infile.seekg (0);
  12.  
  13.   // allocate memory for file content
  14.   char* buffer = new char[size];
  15.     unsigned ii[5] = {0x23, 0x23, 0x23, 0x23, 0x23};
  16.   // read content of infile
  17.   infile.read (buffer,size);
  18.  
  19.   // write to outfile
  20.   //outfile.write (buffer,size);
  21.   outfile.write ((char*)ii,sizeof(ii));
  22.  
  23.   // release dynamically-allocated memory
  24.   delete[] buffer;
  25.  
  26.   outfile.close();
  27.   infile.close();
  28.   return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement