c++ - 如何让 atoi() 函数在字符串上工作?

标签 c++ string itoa

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:\Users\Anthony\Downloads\pack1.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++;
}

关于c++ - 如何让 atoi() 函数在字符串上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27682386/

相关文章:

c++ - 唯一指针和 push_back 函数

javascript - 将一个字符串一分为二,保持单词完整并返回它们

c - uint64_t 到数组 - C 语言

C int 到 Mac OS X 上的 char 数组

c++ - 重载 unique_ptr 运算符调用 make_unique

C++加载文本文件,优化

java - 删除 html 标签

ios - 在 Swift 中查找字符串中第 N 个子字符串实例的索引

c - 我必须下载哪个库才能在 C 中获取 itoa()

c++ - QTextEdit 与 QPlainTextEdit