I'm having more C++ troubles (I know, what else is new? ). This time it's with simple file I/O. My program will not read the specified file at all, and instead displays the "could not open" error message that I created. What is wrong with this program? And before you ask, yes, the '8.txt' file is in the same directory as the program.
I'm anxious to see what mistake I made this time!
PHP:
#include <iostream>
#include <fstream>
#include <cstdlib>
int main()
{
using namespace std;
ifstream fin;
char ch;
int count = 0;
fin.open("8.txt");
if (!fin.is_open())
{
cout << "Could not open the file '8.txt'." << endl;
cout << "Program terminating." << endl;
exit(EXIT_FAILURE);
}
fin.get(ch);
while (fin.good())
{
count++;
fin.get(ch);
}
if (fin.eof())
cout << "End of file reached." << endl;
else if (fin.fail())
cout << "Input terminated by data mismatch." << endl;
else
cout << "Input terminated for unknown reason." << endl;
cout << "Total Characters Read: " << count << endl;
fin.close();
return 0;
}
I'm anxious to see what mistake I made this time!