So I am having a loop issue each time I type in a valid file name after telling my program I want to run it again. It says cannot open file and I do not know why.
I have created .txt files named test,test2,test3,test4. So when I type test.txt it reads the file and it will ask for another file name and I will type test2.txt but it fails to read it. Not sure why. Here is my code.
int count;// Number of word operators
ifstream inFile;// Data file
// Get the filename from the user.
cout << "Enter the filename or type 'quit' to quit: ";
cin >> filename;
inFile.open(filename.c_str());// Attempt to open file
// If file wouldn't open, print message
cout << "Can't open input file" << endl;
count = 0;// Initialize counter
while (inFile>>word)// While input succeeds . . .
cout << count << " words operators were found." << endl;
}while(filename != "quit");