Should I close a file when it wasn't able open?
No, that's not necessary to be done explicitly. (File) streams are closed when going out of scope implicitly always.
The close()
function of a std::iostream()
also is an idempotent operation, and never will harm the streams state beyond the stream gets closed (or never was successfully opened).