这个openFile函数的其他测试用例?

时间:2010-04-04 17:41:47

标签: c++

我试图找出为什么打开文件的功能失败了这个自动编程器我提交我的作业。什么类型的输入会在这里失败,我想不出别的什么?

代码:

bool openFile(ifstream& ins)
{

 char fileName[256];
 cout << "Enter board filename: ";
 cin.getline(fileName,256);

 cout <<  endl << fileName << endl;

 ins.open(fileName);
 if(!ins) {
  ins.clear();
  cout<<"Error opening file"<<endl;
  return false;
 }

 return true;

}

这是'自动编程器'输出我程序输出的内容,以及正确的输出应该是什么(我不知道他们用于输入的文件中有什么)

Autograder output:

*******************************************
*****                                 *****
*****     Your output is:             *****
*****                                 *****
*******************************************
Testing function openFile
Enter board filename:
test.txt
1
Enter board filename:
not a fileName
Error opening file
0


*******************************************
*****                                 *****
*****       Correct  Output           *****
*****                                 *****
*******************************************
Testing function openFile
Enter board filename:
1
Enter board filename:
Error opening file
0

2 个答案:

答案 0 :(得分:0)

嗯,你知道他们使用的输入是什么。它出现在程序的输出中!第一个输入文件名是test.txt,第二个是not a fileName

无论如何,您收到后似乎正在打印文件名。但是没有打印的文件名出现在正确的输出中。只是停止打印它可能有所帮助。

(有没有其他人认为这个自动编程器的设计是愚蠢的?当我被这些东西评分时,他们不会显示我们自己的程序的输出。至少我们必须设置一个SMTP会话才能拥有测试输入通过电子邮件发送给我们......)

答案 1 :(得分:0)

Testing function openFile
Enter board filename:
test.txt
1
Enter board filename:
not a fileName
Error opening file
0

你打印test.txt这是我在输出中看到的唯一区别

相关问题