如果初始打开失败,我正在尝试确定是否需要在 fstream 对象上调用 close。
IE
std::fstream strm;
strm.open( "filename" );
if( ! strm.fail() )
{
// Do something
strm.close(); // [1]
}
strm.close(); // [2]
这里应该在哪里调用close - 应该始终调用 [2] 还是仅在 open 成功 [1] 时调用?
我可能在这里过头了,但是来自通常执行此操作的 Windows API 方式,我有CloseHandle( ... ); 嵌入我的脑海:-)