【发布时间】:2020-07-25 03:32:20
【问题描述】:
我有一个代码 sn-p
if (!boost::filesystem::exists(tempDir)) {
boost::filesystem::create_directories(tempDir);
}
auto path = tempDir / boost::filesystem::unique_path("gfbfv1-%%%%-old");
do_something_maythrow(path);
remove(path);
即使在do_something_maythrow 抛出的情况下,如何确保始终删除路径?
我应该写一个FileDeleter,它采用一个路径并在使用所谓的RAII 概念的析构函数上删除该路径,还是有现有的解决方案?
【问题讨论】:
-
@sehe 我对 c++ 还很陌生,这种“FILE*”返回类型似乎很难与其他接口配合。