why won't ifstream::fail() work?

This is a discussion on why won't ifstream::fail() work? within the C++ Programming forums, part of the General Programming Boards category; hiya, <source> // presume that data.dat is not in my harddisk ifstream fin("data.dat", ios::in); if(fin.fail()) return false; </source> so ehm ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    142

    why won't ifstream::fail() work?

    hiya,

    <source>
    // presume that data.dat is not in my harddisk

    ifstream fin("data.dat", ios::in);
    if(fin.fail())
    return false;
    </source>

    so ehm why doesn't it return false, it creates the file on my hard disk instead, what flag should i use in replace of ios::in?

    many thanks,

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    did you try using .eof() or .good()? ex:
    Code:
    ifstream infile("input.txt",ios::in);
    
    while(infile.good())
    {.......
    }
    or
    Code:
    ifstream infile("input.txt", ios::in);
    
    while(!infile.eof())
    {....
    }

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    well, i used ios::good now it works, but don't know why fail doesn't oh well, as long as it works it's okey,

    thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21