C ++コピーファイル - 伝統的ハンドル例外(学習)

書式#include <iostreamの>
書式#include <stdio.hに>

名前空間stdを使用。

my_copyを(CONSTするchar * SRC_FILE、CONSTのchar * DEST_FILE)がINT
{
  FILEの*のin_file、* out_fileパラ。
  =用のfopen(SRC_FILE、 "RB")in_file。
  (== NULL in_file)であれば
  {
    1を返します。
  }

  out_fileパラ=用のfopen(DEST_FILE、 "WB")。
  (== NULLがOUT_FILE)なら
  、{
    2を返します。
  }

  チャーREC [1024]。
  bytes_in size_tの、bytes_out。
  一方、((bytes_in =のfread(REC、1、1024 in_file))> 0)
  {
    bytes_out = fwriteの(bytes_in REC、1、、out_fileパラ)。
    (もし!bytes_in = bytes_out)
    {
      リターン3。
    }
  }
  にfflush(out_fileパラ)。
  FCLOSE(out_fileパラ)。
  FCLOSE(in_file)。

  0を返します。
}

メインint型()
{
  int型の結果、
  IF((結果= my_copyを( "D:\\ \\ 11.txtファイル"、 "D:\\ \\ \\ 20190608 1.TXTファイル")= 0)!)
  {
    スイッチ(結果)
    {
    ケース1:
      のprintf( "ソースファイルエラー\ nを開く");
      BREAK;
    ケース2:
      のprintf( "ターゲットファイルのエラー\ nを開く");
      BREAK;
    ケース3:
      のprintf(「コピーファイルのエラー\ nを");
      BREAK;
    デフォルト:
      のprintf(" N- \不明なエラー");
      BREAK;
    }
    
  }


  システム(「一時停止」)。
  0を返します。
}

 

おすすめ

転載: www.cnblogs.com/herd/p/10991035.html