我有一个写std::ostream
的小类,但是需要将文件重置为零长度。
我这样做:
namespace config{
constexpr std::ios::openmode MODE = std::ios::out | std::ios::binary | std::ios::trunc;
}
std::ofstream file_data{filename, config::MODE};
//...
file_data = {filename, config::MODE};
这行得通,因为它叫std::ofstream
d-tor,但是应该有更好的方法吗?