看板 MacDev 關於我們 聯絡資訊
今天早上在學校用Visual Studio 2008 寫程式 以下是code: #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std; int main() { char answer; string first; string middle; string last; string name; string age; char sex; ofstream fout("output.txt"); fout << "Name" << setw(16) << "Age" << setw(8) << "Sex" << endl; for(int i=0; i<3; i++) { cout << "Does the employee have middle name (Y/N)?" ; cin >> answer ; cout << "Input the emplyee's name, age, and sex (M/F): " ; if (answer=='Y') { cin >> first >> middle >> last >> age >> sex; name = first + ", " + middle + " " + last; fout << name << setw(20-name.length()) << age << setw(10-age.length()) << sex << endl; } if (answer=='N') { cin >> first >> last >> age >> sex; name = first + ", " + last; fout << name << setw(20-name.length()) << age << setw(10-age.length()) << sex << endl; } } return 0; } 發現一件很奇怪的事情... 我早上用這個code可以輕易做到助教的要求, 但回到家,發現!!! code裡面說要輸入三個name, age, sex 之後 output.txt檔才會完整... 在學校跑都ok 但是在家裡跑卻...(在終端機跑過專案了,也確實打過那些資料) 只fout了「fout << "Name" << setw(16) << "Age" << setw(8) << "Sex" << endl;」 這段code的東西。 我後來cin的資料都沒有顯示在output.txt檔中... 不知道該如何處理? 不行的話...我就要在paralel(不確定拼法對不對啦)灌個VS2008來取代Xcode了... 雖然我覺得Xcode漂亮多了!! 感謝大大~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.160.31
ducksteven:開 Xcode 的 debugger 吧! 04/01 23:15
appleway:你沒有關檔。 04/02 00:21
raytekimo:想請問一下debugger的用意是什麼?關檔是關終端機還是? 04/02 22:07
raytekimo:謝謝 04/02 22:07
appleway:你的code裡面只有開檔沒有close file 04/03 01:16
appleway:fout 有可能都先放在buffer 關檔的時候一口氣寫進去 04/03 01:16
raytekimo: 喔喔我大概了解了!應該是說fout.close()吧!謝謝~ 04/03 23:16