我正在试图弄清楚为什么我打开文件的功能没有通过这个提交作业的自动阅卷器。什么类型的输入会在这里失败,我想不出其他什么了?
代码:
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
发布于 2010-04-05 01:46:26
嗯,你一定知道他们使用的输入是什么。它出现在你的程序的输出中!第一个输入文件名是test.txt
,第二个是not a fileName
。
不管怎样,看起来你是在收到文件名之后才打印出来的。但是在正确的输出中没有显示打印的文件名。别再打印了可能会有帮助。
(有没有人认为这个自动分级机的设计很愚蠢?当我被这些东西打分的时候,他们不会显示我们自己的程序的输出。至少我们必须设置一个SMTP会话,以便将测试输入通过电子邮件发送给我们……)
发布于 2010-04-05 01:48:02
Testing function openFile
Enter board filename:
test.txt
1
Enter board filename:
not a fileName
Error opening file
0
您的输出会打印出test.txt
,这是我在输出中看到的唯一区别
https://stackoverflow.com/questions/2575293
复制相似问题