need help with file opening errors
hi! i have a question about file opening. i'm supposed to allow a user to enter filenames of 5 text files. here is a portion of my code.
it works fine if the file can be found everytime.
cout << "Enter filename(e.g abc.txt): ";
cin >> filename;
cout << "Error!\n";
inFile >> f;
}while(file_count < 5);
i thought i have closed my file after each round so it doesnt matter. but after typing an incorrect filename once the program will state that inFile failed even though i typed a valid filename.
anyone knows whats wrong with this?
also, i changed the extension of another file type to .txt and tried opening it within the program. this causes the program to hang. just wondering is there's a way to test if the file is really a .txt before opening it. my aim is for the program to handle all invalid files properly..
i thank all who are willing to help or even spend time reading about my problem. =)