我想弄清楚爲什麼我的函數打開一個文件是失敗這個autograder我提交我的作業。什麼類型的輸入會在這裏失敗,我想不出其他什麼?這個openFile函數的其他測試用例?
代碼:
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」輸出(我不知道是什麼他們使用的輸入文件)
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-04 18:07:06