我有存儲ASCII表格的麻煩我不想用我的手寫出所有255個表格,我需要將它們存儲在散列表中以便壓縮字符串文件尊重Ziv-Lempel算法。那麼你是否有任何建議,以另一種方式將它們存儲在散列表中?如何在C++中存儲ASCII表格
謝謝。
編輯:(感謝您的答覆我想,這是一個非常基本的問題,遺憾的是)
HashTable::HashTable(){
char charToBeStored;
theList.resize(4096);
for(int i= 0; i<256; i++){
charToBeStored = i;
string stringToBeStored = charToBeStored; //Problem is here I also need to store
// strings beside char. I need to store them both
theList.push_back(charToBeStored); // Used <vectors> -> vector<string> theList;
}
}
解決
HashTable::HashTable(){
unsigned char charToBeStored;
theList.resize(4096);
for(int i= 0; i<256; i++){
charToBeStored = i;
string stringToBeStored = "";
stringToBeStored += charToBeStored;
theList.push_back(stringToBeStored);
}
}
我不確定你的意思。如果你將一個'static'字符串轉換爲'int',它會給你該字符的ASCII值:'static_cast('a')'給出97. –