共有ポインタ

書式#include <文字列>
の#include <fstreamの>
の#include <メモリ>
書式#include <cstdioを>

クラスFileDeleter
{
  プライベート:
    STD ::文字列のファイル名。
  公共:
    FileDeleter(CONSTのstd ::文字列&FN)
    :ファイル名(FN){}

    ボイド演算子()(STD :: ofstreamのの*のFP){
      FP->近いです();
      std ::削除(filename.c_str());
    }
}。

メインINT()
{
  のstd :: shared_ptrの<のstd :: ofstreamの> FP(新しいSTD :: ofstreamの( "tmpfile.txt")、FileDeleter( "tmpfile.txt"));
}

 

おすすめ

転載: www.cnblogs.com/herd/p/10955016.html
おすすめ