0
void BinaryTree::InitializeFromFile(string Filename){
ifstream inFile;
treenode* Freq[256];
inFile.open(Filename.c_str(), fstream::binary);
if(inFile.fail()){
cout<<"Error in opening file "<<Filename;
return;
}
for(int i=0;i<=255;i++){
Freq[i]->weight=0;
Freq[i]->data = '0'+i;
Freq[i]->LChild = NULL; Freq[i]->RChild=NULL; Freq[i]->Parent=NULL;
}
char c;
inFile.get(c);
while(!inFile.eof()){
Freq[c]->weight ++;
inFile.get(c);
}
}
我在for循環中收到訪問衝突異常。即使當我註釋掉某些行時,它也會在該循環的下一行中給我一個錯誤。初始化數組時初始化System.AccessViolationException
編輯:另外是行Freq[c]->weight ++;
有效?我可以根據char值轉到數組的特定部分嗎?
* Facepalm *謝謝,我很驚訝,我忘了初始化它。任何我的編輯答案? – Azreal 2010-02-27 18:55:25
我讀過一天Don Knuth的文字,描述他在TeX開發過程中犯的愚蠢錯誤;人們只是人,每個人都會犯錯誤。關於你的編輯:'Freq [c] - > weight ++'似乎完全沒問題。 – Vlad 2010-02-27 19:21:24