I can't believe I'm asking this because I've done this before, but for some reason it's not working. I'm asking the user to give me the name of a file. If the file doesn't exist or does not open, I want it to prompt them again until they give me a good file name. The code I'm using now is:
1 2 3 4 5 6 7 8 9 10 11 12
do
{
cout << "\nPlease enter the file path: ";
cin >> file;
fileName.open(file.c_str( ));
if (fileName.fail())
{
cout << "\Error!";
fileName.clear( );
}
}while (fileName.fail());
Everything works great if they give me a good file name, but that's it... If they give me a bad file name, it doesn't work. Any suggestions?