2013-11-27 27 views
-1

我有存儲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); 
    } 
} 
+0

我不確定你的意思。如果你將一個'static'字符串轉換爲'int',它會給你該字符的ASCII值:'static_cast ('a')'給出97. –

回答

0

ASCII只是0到255,所以寫一個for循環,將無符號字符存儲到哈希表中,從0到255.

+0

當你提到我做了那個,但現在我必須存儲字符串這個列表(我使用矢量)。 – Kaan

0

生成所有ascii字符:

char[256] asciichars; 
for(int i = 0;i<256;++i) 
{ 
    char[i] = static_cast<char>(i); 
} 
+0

謝謝,我在代碼中添加了我的代碼。 – Kaan