I am using the following code:
(IN MAIN)
When I enter the file name correctly the FIRST TIME it works fine, but I want the users to be able to make a mistake and type in another path, However, if you type in a wrong file path the first time, no matter what, it will always come back false after that, no matter how many times you try. Please Help.Code:do { fileOpen = OpenInputFile(infile, inputpath); } while (!fileOpen); (OUT OF MAIN) bool OpenInputFile(ifstream& infile, string& inputpath) { // prompt user for input file names cout << "Input the name of the input file" << endl; cin >> inputpath; //open file and verify its presence infile.open(inputpath.c_str()); if (infile.fail()) { cout << "Sorry, the file '" << inputpath << "' was not found." << endl; cout << "Input another path" << endl; return false; } // notify user if opening was a success cout << "Input file '" << inputpath << "' is open for reading" << endl; return true; }
PS don't laugh at my failuresome attempt at writing code.