我想我可能需要使用一個布爾bValue = false爲我而條件:ifstream的object.eof()不工作
char cArray[ 100 ] = "";
ifstream object;
cout << "Enter full path name: ";
cin.getline(cArray, 100);
if (!object) return -1 // Path is not valid? This statement executes why?
ifstream object.open(cArray, 100);
// read the contents of a text file until we hit eof.
while (!object.eof())
{
// parse the file here
}
爲什麼我不能進入文本文件的全路徑名?
這可能是因爲eof。他們的語法是否可以模擬eof的布爾語句?
我可以有:
while (!object == true)
{
// parase contents of file
}
你沒有一個C++編譯器編譯這段代碼,除非你推翻錯誤莫名其妙。你是否從實際編譯的內容中重新輸入了它?也許你應該複製和粘貼你確實有問題的代碼。 – 2009-04-08 17:48:13