[英]ifstream for breaking hashed strings
嗨,我想使用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());
您還需要檢查讀取是否成功。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.