I want to open a file, write to it, and properly check all error possibilities with QFile
. I have found how to this with 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.
}
Can I do error checking in a similar way if I use operator<<()
with QFile
?
What I have found is to use the write
method and compare the return value with the length of string to write.