2012-12-01 50 views
2

您好我想阅读使用ifstream哈希值的txt文件并将值存储在数组中。ifstream打破散列字符串

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点打字。

+0

给出一个输入示例。 – xiaoyi

回答

1

如果哈希值是不换行符号或空格商店,你可以尝试这样的事:

std::vector<char> hash(16); 
myfile.read(&hash[0], 16); 
data_arr.push_back(std::string(hash.begin(), hash.end()); 

你还需要检查,如果阅读是成功的。