【发布时间】:2013-11-27 21:09:44
【问题描述】:
我在存储 ASCII 表时遇到了麻烦,我不想手动编写所有 255 个表,我需要将它们存储在哈希表中,以便根据 Ziv-Lempel 算法压缩字符串文件。那么您有什么建议吗?还有其他方法可以将它们存储在哈希表中吗?
谢谢。
已编辑:
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_castachar到int它会给你字符的 ASCII 值:static_cast<int>('a')给出 97。
标签: c++ compression hashtable