A
Asger-P
Hi
I never used ifstream and ofstream before, so I searched a little
and made this little function, for removing BOM's in php files.
It works fine, I just want to make sure that I'm doing it right.
void __fastcall removeBOM(char* fileName)
{
ifstream ifile(fileName, ios::in | ios::binary | ios::nocreate);
if( ! ifile )
return;
unsigned char Bom[3];
ifile.seekg( 0 );
ifile.read ( Bom, 3 );
if( Bom[0] == 0xEF && Bom[1] == 0xBB && Bom[2] == 0xBF )
{
bool Done = false;
string tmpFile = fileName;
tmpFile += "tmptmp";
ofstream ofile( tmpFile.c_str() );
if( ofile )
{
ofile << ifile.rdbuf();
ofile.close();
Done = true;
}
ifile.close();
//renaming and deleting files
return;
}
ifile.close();
}
in particular this line:
if( ! ifile )
isn't that always true on an refference ?
Best regards
Asger-P
I never used ifstream and ofstream before, so I searched a little
and made this little function, for removing BOM's in php files.
It works fine, I just want to make sure that I'm doing it right.
void __fastcall removeBOM(char* fileName)
{
ifstream ifile(fileName, ios::in | ios::binary | ios::nocreate);
if( ! ifile )
return;
unsigned char Bom[3];
ifile.seekg( 0 );
ifile.read ( Bom, 3 );
if( Bom[0] == 0xEF && Bom[1] == 0xBB && Bom[2] == 0xBF )
{
bool Done = false;
string tmpFile = fileName;
tmpFile += "tmptmp";
ofstream ofile( tmpFile.c_str() );
if( ofile )
{
ofile << ifile.rdbuf();
ofile.close();
Done = true;
}
ifile.close();
//renaming and deleting files
return;
}
ifile.close();
}
in particular this line:
if( ! ifile )
isn't that always true on an refference ?
Best regards
Asger-P