fail

To test for stream reading failure from any cause.

  bool fail() const
  
Remarks

The member function fail() will test for failbit and badbit.

Returns true if failbit or badbit is set in rdstate().

Listing: Example of fail() usage
// ewl-test file for input contains.
// float 33.33 double 3.16e+10 Integer 789 character C

#include <iostream>

#include <fstream>

#include <cstdlib>

int main()

{

using namespace std;

   char inFile[] = "ewl-test";

   ifstream in(inFile);

   if(!in.is_open()) 

   {cout << "Cannot open input file"; exit(1);}

   char ch = 0;

   while(!in.fail()) 

   {

      if(ch)cout.put(ch);

      in.get(ch);

   }

   

   return 0;

}

Result:

  float 33.33 double 3.16e+10 integer 789 character C