"Jorge Rivera" <jorgeri@rochester.rr.com> wrote in message
news:nzy_b.83371$%72.49644@twister.nyroc.rr.com...[color=blue]
> ben wrote:[color=green]
> > Hello,
> >
> > This really drives me nuts.
> > Im opening an input file, and Im testing if it was open successfully.[/color][/color]
Thats[color=blue][color=green]
> > it!
> > I know that the file that Im trying to open DOES NOT exist but Im[/color][/color]
getting NO[color=blue][color=green]
> > error message.
> > No matter what name I enter I get 'file opened successfully"
> > Any clues? Thanks!
> >
> > #include <iostream.h>
> > #include <stdlib.h>
> > #include <stdio.h>
> > #include <fstream.h>
> >
> > int main()
> > {
> > ifstream infile;
> > char file_name[16];
> >
> > printf("\nEnter file name: ");
> > cin>>file_name;
> >
> > infile.open(file_name);
> >
> > if (infile.fail())[/color]
>
> Truy replacing this for
> if(infile)[/color]
I left my std at work but according to an online reference at
http://www.cplusplus.com/ref/iostrea...torvoidpt.html
This should be the same as fail() i.e. badbit or failbit
An alternative would be to check for !good() as good includes eofbit
The online ref had nothing to say about the specific behaviour of open which
is interesting in itself.
P.S. do you get failbit when you actually try to use it?
[color=blue][color=green]
> > printf("cant open %s",file_name);
> > else
> > printf("\nfile %s opened succesfully\n",file_name);
> >
> > infile.close();
> > return 0;
> > }
> >
> >[/color][/color]