1. #include <fstream>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. void mv(std::string const &fname_from, std::string const &fname_to) {
  6.  
  7.     std::ifstream from(fname_from, std::ios_base::in | std::ios_base::binary); // open file for reading
  8.     if (!from) {
  9.         std::cerr << "Can't open " << fname_from << " for reading.\n";
  10.         throw 1;
  11.     }
  12.  
  13.     std::ofstream to(fname_to, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
  14.     if (!to) {
  15.         std::cerr << "Can't open " << fname_to << " for writing.\n";
  16.         throw 1;
  17.     }
  18.  
  19.     char c;
  20.     while (from.get(c))
  21.         if (!to.put(c)) {
  22.             std::cerr << "Error writing to " << fname_to << '\n';
  23.             throw 1;
  24.         }
  25. }
  26.  
  27. int main() {
  28.     mv ("a.exe", "b.exe");
  29. }