I am trying to make a loop that repeats untill I get a valid file name from the user. Unfortunatly it only works if the correct file name is input on the first attempt. Can someone give me some ideas in the right direction on what I am doing wrong?
Code:cout << "Please enter the name of the file to open: "; cin >> fileName; cout << "You entered:" << fileName << endl; inFile.open(fileName.c_str()); while (!inFile) { cout << "Please enter the name of the file to open: "; cin >> fileName; cout << "You entered:" << fileName << endl; inFile.open(fileName.c_str()); }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.