嗨,我想使用 ifstream 读取哈希值的 txt 文件并将值存储在数组中。
128 位哈希字符串另一个 128 个散列字符串等
这是我到目前为止所拥有的:
string line;
ifstream myfile ("username.txt");
vector<string> data_arr;
int i = 0;
if (myfile.is_open())
{
while (myfile.good())
{
getline(myfile, line);
data_arr.push_back(line);
i++;
}
myfile.close();
}
else cout << "Unable to open file";
如何使数组的每个值长度为 16 个字节?我猜 getline 对我不起作用,因为哈希值可以让换行符标签成为字符的一部分。
无论如何,我希望这是有道理的,(可能不是),因为我在早上 5 点打字。
如果哈希是没有换行符或空格的存储,您可以尝试这样的事情:
std::vector<char> hash(16);
myfile.read(&hash[0], 16);
data_arr.push_back(std::string(hash.begin(), hash.end());
您还需要检查读取是否成功。