2011-11-21 75 views
0

編輯:解決了...使用相同的ifstream多個文件顯然不是一個好主意。C++文本文件現在不工作?

我剛買了一臺新的筆記本電腦,並且已經轉移我的C++項目到新電腦,我突然用從代碼:: Blocks的閱讀文本文件的問題...我不知道爲什麼。

舊膝上型跑了32位操作系統,而新的一個是64位。我不知道這是否會影響任何事情。

這裏的代碼工作的部分,其不再:

ifstream myfile; 
//edit: a different file is read here, in exactly the same manner as below 
//when I comment it out, the following section works as it's meant to... 
//what am I doing wrong that they won't work successively 

myfile.open("version.txt"); 

if (myfile.is_open()) { 
    out("This message displays..."); 
    //OK so apparently 'eofbit' is thrown here...but the file has content in it? 
    while (myfile.good()) { 
     out("This message doesn't, when it should..."); 
     getline(myfile,version_info); 
    } 
    myfile.close(); 
} 

編輯:「出」僅僅是一個自定義腳本顯示一條消息,順便說一句。

+0

編譯爲32或64位的代碼? –

+1

您是否嘗試過調試? –

+0

@Preet Sangha我重建了64位筆記本電腦上的整個項目,所以我假設。它在32位筆記本電腦上工作,其他所有工作都在64位筆記本電腦上工作,只是不是文件... – Matthew

回答

0

嘗試使用myFile.rdstate(),以確定是什麼原因造成的錯誤看到here

+0

試過了,沒有結果... – Matthew

+0

哪個狀態返回了? – smitec

+0

沒有一個......甚至沒有一個。 – Matthew