我正在尝试逐行哈希文件的内容。我想过的过程是获取字符串的最后一个字符,然后哈希该最后一个字符,但这给我带来了问题。任何帮助,将不胜感激。
int HashTable::hashFunction(string key) {
char last = key[14]; //--->>!!!! the problem happens here where an out of range error pops up
///although the string passed is 16 characters long
int ila = int(last) - 48; //CONVERT LAST CHARACTER TO INTEGER
return ila % hashGroups;
}
void HashTable::read_from_file() {
fstream myfile;
string input, pass, account number;
myfile.open(address1.c_str(), ios::in);
while (!(myfile.eof())) {
getline(myfile, account number, ',');
getline(myfile, pass, '\n');
int hashValue = hashFunction(account number);
}
myfile.close();
}