N
Nobody You Know
My goal is to efficiently read a file into a c++ string, discarding
newlines. Here is my first cut:
bool MyClass::ReadFile( string strFileName )
{
ifstream File( strFileName.c_str() );
if ( !File )
{
return false;
}
else
{
m_strFileData.reserve( 10000 );
char Char;
while ( File.get( Char ) )
{
if ( Char != '\n' )
m_strFileData += Char;
}
File.clear();
File.close();
return true;
}
}
I'm sure there's a better (i.e., faster) way. Can anyone help out?
Thanks!
newlines. Here is my first cut:
bool MyClass::ReadFile( string strFileName )
{
ifstream File( strFileName.c_str() );
if ( !File )
{
return false;
}
else
{
m_strFileData.reserve( 10000 );
char Char;
while ( File.get( Char ) )
{
if ( Char != '\n' )
m_strFileData += Char;
}
File.clear();
File.close();
return true;
}
}
I'm sure there's a better (i.e., faster) way. Can anyone help out?
Thanks!