I want to write a wrapper around fstream
class. As I can see the most common way to check if stream works well is to see result of good()
function. However, I've heard that this is mostly historical function and it is not really safe to use it (to be more correct, there may be some situations when stream doesn't work well but function returns true
. So I'd like to share experience and to know from others what is the most correct way to check fstream
for errors.
It would be great if there could be a possibility to check different types of errors like if file doesn't exist, can be opened only for reading, etc. It is also necessary to leave such programs to be crossplatform (however, the main target is Linux).
Thanks in advance!