Search code examples
c++linuxfstream

what would make ios::fail() evaluate to 1?


i am trying to open a file with

27   string tline;
28   ifstream finp; // input file
29   ifstream dinp; // data files
30 
31   finp.open(argv[1]);
32 
33 
34   cout << "finp.good() = " << finp.good() << endl;
35   cout << "finp.bad() = " << finp.bad() << endl;
36   cout << "finp.fail() = " << finp.fail() << endl;

and i end up with output

finp.good() = 0
finp.bad() = 0
finp.fail() = 1

now, i cannot find any good documentation on what would cause this other than that it is an internal logic problem. what am i supposed to do to correct this?

if it helps, i am running on linux where i need to include both <cstring> and <cstdlib> while i do not have to do this when running on OSX. could this be the problem? if so, how do i correct it?


Solution

  • forgive me, i made a simple mistake. when i ported my source files over to the linux system, i had ported over a script as well. i was confusing the executable with the script and the script had a filename hardcoded into it which was not in the directory.

    basically, i was accidentally trying to read a file which was not there!