开发者

Other test cases for this openFile function?

开发者 https://www.devze.com 2022-12-25 09:13 出处:网络
I am trying to figure out why my function to open a file is failing this autograder I submit my homework into. What type of input would fail here, I can\'t think of anything else?

I am trying to figure out why my function to open a file is failing this autograder I submit my homework into. What type of input would fail here, I can't think of anything else?

Code:

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;

}

Here is output from the 'Autograder' of what my program's output is, and what the correct output is supposed to be (and I do not know what is in the file they use for the input)

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


Well, you do know what the input is that they use. It appears in your program's output! The first input file name is test.txt, the second is not a fileName.

Anyway, it seems that you're printing the filename after you receive it. But no printed filename appears in the correct output. Just stop printing it might help.

(Does anyone else think that the design of this autograder is stupid? When I was being graded by those things, they wouldn't show our own program's output. At least we'd have to set up an SMTP session to have the test input e-mailed to us...)


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

Yours prints out test.txt That is the only difference I see in the outputs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号