2010-04-04 25 views
0

我想弄清楚爲什麼我的函數打開一個文件是失敗這個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 
+0

只是不寫名後面的唯一區別。 – 2010-04-04 18:07:06

回答

0

好,你做知道輸入是什麼,他們使用。它出現在你的程序輸出中!第一個輸入文件名是test.txt,第二個是not a fileName

無論如何,它似乎是你收到它後打印文件名。但是沒有打印的文件名出現在正確的輸出中。只需停止打印它可能會有幫助。

(還有人認爲這個autograder的設計是愚蠢的嗎?當我被這些東西評分時,他們不會顯示我們自己的程序的輸出。至少我們必須設置一個SMTP會話來有測試輸入電子郵件發送給我們...)

+0

這可能是它。 fwiw,我們得到了程序應該表現的一個.exe文件,並且它們的版本REPRINTED文件名。啊。 – codefail 2010-04-04 18:16:49

+0

我可以看到這是如何令人困惑... – Thomas 2010-04-04 19:10:34

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

此致打印出test.txt這是我在輸出看

相關問題