如何让 atoi() 函数处理字符串

How can I get the atoi() function to work on a string?

本文关键字:函数 处理 字符串 atoi      更新时间:2023-10-16
int p; long unsigned int z;
while (i <= x.length())
{
    const int a = x.length();
    char* b;
    b = x.substr(sizeof(a) - i, 1);
    p = atoi(b);
    z = (z + p + 3) * 3;
    i++;
}

我得到:

C:UsersAnthonyDownloadspack1.cpp|77|error: cannot convert 'std::basic_string<char>' to 'char*' in assignment|

我试图通过"x"向后向下,并随时写下每个 ascii 代码。底部的公式是一个哈希。"x"是文件名。我稍后会解开它。我需要通过 atoi() 运行它。

请帮忙,因为我不知道该怎么办。 程序中的其他一切都运行良好,但至于这一点,我对这可能是不可能的真实性感到有点不安。请帮忙,谢谢。

int p; long unsigned int z;
while (i <= x.length())
{
  const int a = x.length();
  string b;
  b = x.substr(sizeof(a) - i, 1);
  p = atoi(b.c_str());
  z = (z + p + 3) * 3;
  i++;
}