Error checking read files

June 6, 2009 at 11:14:14
Specs: Windows XP
I am a beginner trying to read a file name, and if correct, send the data elsewhere. But if the filename is incorrect, or doesn't exist, then the user is asked to input the filename again.

When I error check, I input a bad filename in first, then try the correct one. This doesn't work, it just repeats the loop and keeps on asking for a new filename, even if the file is correct.

What am i doing wrong here? the character array is already defined elsewhere

Here is the filename loop:

ifstream input;

do {

cout << "Please enter a filename: ";
cin >> filename;;

if( {cout << " Error: Cannot open file! Try Again!" << endl;}


See More: Error checking read files

Report •

June 6, 2009 at 14:25:14
Sorry, I solved it by utilizing the bool function when it is called. Works fine when you get rid of the loop, and return false when returns true. Then where the function is called you loop that until it is true.

Report •
Related Solutions

Ask Question