【发布时间】:2018-02-06 08:06:08
【问题描述】:
我想用QFile 打开一个文件,写入它,并正确检查所有可能的错误。我有found 如何使用std::ofstream:
std::ofstream f(...);
// all sorts of output (usually to the `std::ostream&` in a
// function).
f.close();
if ( ! f ) {
// Error handling. Most important, do _not_ return 0 from
// main, but EXIT_FAILUREl.
}
如果我将operator<<() 与QFile 一起使用,是否可以以类似的方式进行错误检查?
我发现是使用write方法并将返回值与要写入的字符串长度进行比较。
【问题讨论】: