fstream file I/O question
Posted
by Konrad
on Stack Overflow
See other posts from Stack Overflow
or by Konrad
Published on 2010-05-12T15:20:04Z
Indexed on
2010/05/12
15:24 UTC
Read the original article
Hit count: 172
Hi,
I am trying to work out if I need to call close on a fstream object if the intial open failed.
i.e.
std::fstream strm;
strm.open( "filename" );
if( ! strm.fail() )
{
// Do something
strm.close(); // [1]
}
strm.close(); // [2]
Where should close be called here - should it always be called [2] or only if the open succeeds[1]?
I may be going over the top here, but coming from the Windows API way of typically doing this I have CloseHandle( ... ); embedded in my mind :-)
© Stack Overflow or respective owner