为何fstream::is_open()不能正常工作?
我在VS2010的环境下执行代码,但是文件操作却不能正常实现后来发现,文件根本就没有打开,在
std :: ofstream fFile( "MyFile.in" );
这一行,文件没有打开,但是在紧接着的
if( !fFile.is_open() )
{
return false;
}
中,它竟然没有返回,而是继续向下
后来经过测试,无论文件名是什么,is_open()都不能正常工作
都会返回true
原始代码如下:
inline bool MyClass :: OutputToFile( std :: string szFileName ) const
{
std :: ofstream fFile( szFileName );
if( !fFile.is_open() )
{
return false;
}
fFile.seekp( std :: ios :: beg );
for( unsigned int i = 0 ; i < m_szString.size() ; i++ )
{
fFile.put( m_szString[ i ] );
}
fFile.close();
return true;
}求解释,求帮助
页:
[1]