Click to See Complete Forum and Search --> : if(!infile) in c++


Gaccm
12-10-2000, 01:59 AM
i ported a program from win and i have a point where the user is supposed to input a file name and if if it not present to say "file not found" the code worked on win, but now if a inputted file doesn't exist, i get a "Floating point exception". does anyone know how to fix this?

f'lar
12-10-2000, 05:21 AM
I think you want to use the .good() function. Assumeing infile is the name of the stream, not the file, it would be something like:
if (!infile.good())
{
cout << "File not found";
exit(-1);
}
else
{
...
}


------------------
If life were fair, we'd all be in Hell already.