1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. void FileState(ifstream &in);
  5. int main(int argc, char *argv[])
  6. {
  7. ifstream inFile(“C:\NEWS.txt”);
  8. if(!inFile)
  9. {
  10. cout << “Cannot open input file.n;
  11. return 1;
  12. }
  13. char currChar;
  14. while(inFile.get(currChar))
  15. {
  16. cout << currChar;
  17. FileState(inFile);
  18. }
  19. FileState(inFile);
  20. inFile.close();
  21. system(“PAUSE”);
  22. return 0;
  23. }
  24. void FileState(ifstream &inFile)
  25. {
  26. ios::iostate currState;
  27. currState = inFile.rdstate();
  28. if(currState & ios::eofbit)
  29. {
  30. cout << “End of Filen;
  31. }
  32. else if(currState & ios::failbit)
  33. {
  34. // Recoverable I/O error
  35. cout << “Reading Failuren;
  36. }
  37. else if(currState & ios::badbit)
  38. {
  39. // Unrecoverable I/O error
  40. cout << “Stream Corruptedn;
  41. }
  42. }