程序读取文件后,从文件中获取字符,并完成后,询问用户是否需要读取其他文件。如果用户说是,那么程序要求提供文件名,但随后会自动说该文件无法打开并退出循环。请帮帮我。C++后续文件在第一个文件后无法打开
下面是代码:
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
你尝试调试?您试图打开的文件名是否有意义? – 2012-03-21 03:30:29
什么是一个好的调试器? – 2012-03-21 03:32:14
你会得到什么错误?你在哪个系统上运行? 'gdb'是一个流行的调试器,但是你使用的将取决于你使用的是什么系统。 – 2012-03-21 03:33:08