trying to get the program to close if the user inputs "exit" for filename but the if statement isn't returning true and the code just skips over it (sorry for the bad formatting this is my first post)
string filename = "hello";
ifstream fin;
int count = 0;
int arr[9] = { 0 };
cout << " ~Word Counter~ " << endl;
cout << "What file would you like a report on (or type exit to quit): ";
cin >> filename;
if (filename == "exit")
{
exit;
}
fin.open(filename);
while (fin.fail() == 1)
{
cout << "File " << filename << " could not be found." << endl;
cout << "What file would you like a report on (or type exit to quit): ";
cin >> filename;
But you should avoid using exit. It's from C, and doesn't account for C++ stack unwinding (automatic destruction of objects). Prefer to just return from the function.
e.g. return 0; to indicate success from main, return 1; or some other non-zero value to indicate failure from main.