有没有办法截断ostream?

时间:2020-07-16 20:38:28

标签: c++ ostream

我有一个写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,但是应该有更好的方法吗?

0 个答案:

没有答案