【问题标题】:ifstream for breaking hashed stringsifstream 用于破坏散列字符串
【发布时间】:2012-12-01 10:11:22
【问题描述】:

您好,我想使用 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 点输入的。

【问题讨论】:

    标签: c++ arrays ifstream


    【解决方案1】:

    如果哈希是没有换行符或空格的存储,您可以尝试以下操作:

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

    您还需要检查是否读取成功。

    【讨论】:

      猜你喜欢
      • 2011-12-25
      • 1970-01-01
      • 2013-05-29
      • 2011-05-11
      • 2011-07-10
      • 2017-12-11
      • 2011-09-30
      • 1970-01-01
      • 2020-03-17
      相关资源
      最近更新 更多