在程序读取文件、从文件中获取字符并完成后,会询问用户是否要读取另一个文件。如果用户说是,那么程序会询问文件名,但随后会自动说文件无法打开并退出循环。请帮我。
这是代码:
do //do while opening the source file fails
{
cout << "Enter filename of source file: ";
cin.getline (filename,51);
sourceFile.open(filename); //opens the file with given filename
if (sourceFile.fail())
cout << "File could not be opened" << endl; //error if can't open
sourceFile.clear();
}
while (sourceFile.fail()); //exits if source file doesn't fail