我有存储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);
}
}
答案 0 :(得分:0)
ASCII只是0到255,所以写一个for循环,将无符号字符存储到0到255的哈希表中。
答案 1 :(得分:0)
生成所有ascii字符:
char[256] asciichars;
for(int i = 0;i<256;++i)
{
char[i] = static_cast<char>(i);
}