The program is designed to take a file name as a string. My issue here is with the loop, what I want to do with this program is check and see if the file name is good, or if it is bad. And if it's bad, allow the user to re-enter a new file name, however, after it takes in one bad file, it stays in the loop infinitely. What am I doing wrong? I've spent most of the day trying to figure this out.
cout << "Please enter the name of the file you wish to decrypt.\n" <<
"The file must contain no spaces and be less than 25 characters " <<
"in length: " << endl;
cin >> userFile;
ifstream inputFile;//Using fstream operator to Input File Stream.
inputFile.open(userFile);//Assigns the file to the sting entered by the user and opens file
if(!inputFile.good())
{
while(!inputFile.good())
{
inputFile.close();
cout << "------------------------------------------------------------\n";
cout << "\nError!! File name must be no greater than 25 Characters!!!";//Error message print out
cout << "\nPlease enter the name of the file you wish to decrypt.\n" <<
"\nPlease make sure you have the correct directory and\n"
<< "that you have entered '.txt' after your file name."
<< endl;
cin >> userFile;
ifstream inputFile;//Using fstream operator to Input File Stream.
inputFile.open(userFile);//Assigns the file to the sting entered by the user and opens file
}
}
cout << "Please enter the name of the file you wish to decrypt.\n" <<
"The file must contain no spaces and be less than 25 characters " <<
"in length: " << endl;
cin >> userFile;
ifstream inputFile;//Using fstream operator to Input File Stream.
inputFile.open(userFile);//Assigns the file to the sting entered by the user and opens file
while(!inputFile.good())
{
inputFile.clear();
cout << "------------------------------------------------------------\n";
cout << "\nError!! File name must be no greater than 25 Characters!!!";//Error message print out
cout << "\nPlease enter the name of the file you wish to decrypt.\n" <<
"\nPlease make sure you have the correct directory and\n"
<< "that you have entered '.txt' after your file name."
<< endl;
cin >> userFile;
inputFile.open(userFile);//Assigns the file to the sting entered by the user and opens file
}