Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #9966
| Newsgroups | comp.lang.c++ |
|---|---|
| Subject | ifstream ofstream ? |
| Date | 2011-09-09 12:16 +0200 |
| From | Asger-P <junk@asger-p.dk> |
| Organization | Asger-P |
| Message-ID | <op.v1jdhqlu2juju3@ajwin7> (permalink) |
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
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
ifstream ofstream ? Asger-P <junk@asger-p.dk> - 2011-09-09 12:16 +0200
Re: ifstream ofstream ? Goran <goran.pusic@gmail.com> - 2011-09-09 03:56 -0700
Re: ifstream ofstream ? Asger-P <junk@asger-p.dk> - 2011-09-09 13:18 +0200
Re: ifstream ofstream ? Goran <goran.pusic@gmail.com> - 2011-09-09 06:00 -0700
Re: ifstream ofstream ? Asger-P <junk@asger-p.dk> - 2011-09-09 15:17 +0200
Re: ifstream ofstream ? Goran <goran.pusic@gmail.com> - 2011-09-09 06:55 -0700
Re: ifstream ofstream ? Asger-P <junk@asger-p.dk> - 2011-09-09 16:22 +0200
Re: ifstream ofstream ? Goran <goran.pusic@gmail.com> - 2011-09-09 07:39 -0700
Re: ifstream ofstream ? Stuart Redmann <DerTopper@web.de> - 2011-09-09 08:05 -0700
Re: ifstream ofstream ? Goran <goran.pusic@gmail.com> - 2011-09-09 08:18 -0700
Re: ifstream ofstream ? Asger-P <junk@asger-p.dk> - 2011-09-09 17:07 +0200
Re: ifstream ofstream ? Nobody <nobody@nowhere.com> - 2011-09-10 10:23 +0100
csiph-web