将字符串转换为整数参数

Converting a string into an integer parameter

本文关键字:整数 参数 转换 字符串      更新时间:2023-10-16

可能的重复:
如何在C++中将数字转换为字符串,反之亦然
c++-将指针字符串转换为整数

有没有一种方法可以在没有任何大算法的情况下将字符串转换为整数参数?

string = "100";
integerFunction(int string);

我尝试过atoi函数,并尝试用字符串[count]-48手动转换每个数字,但它需要以数字数量不会成为问题的方式进行转换。有什么建议或算法可以帮助吗?我真的很感激。

像这样:

int StringToInt( const std::string & str )
{
  std::stringstream ss(str);
  int res = 0;
  ss >> res;
  return res
}