Hi!
I was wondering why my code works in some cases and not in others. This code is part of a function call that loads information into a vector, then it goes back to a menu. I'm trying to check to see if the filename entered is valid. If I enter a valid filename the first time around, everything works fine. But if I enter an invalid filename, I'm brought back to the menu, and then when I go into the load function again, even if I enter a valid file name it tells me that it is not valid. I don't understand why...
Any suggestions or comments would be appreciated.
[code]
cout << "\n\nPlease enter the name of the file: ";
cin >> filename;
infile.open(filename.c_str());
if (!infile)
{
cout << "\n\nThat is not a valid file. Please try again.\n\n";
} // End if
else if (infile.good())
{
while (!infile.eof())
{
Puts files in vector
} // End while
infile.close();
} // End if
Menu( );