将字符串(char *不是字符串类型)转换为整数

时间:2013-11-22 19:09:26

标签: c++

我想将两个char *类型的变量转换为cpp

中的int
char* lower = "552"
char* higher = "882"

这两个变量是数字,但在char *的类型中,如“552”,我想将它们转换为int,如:

int e = 552 //which 552 is converted from char*

CPP是否有为我这样做的功能?

2 个答案:

答案 0 :(得分:0)

http://www.cplusplus.com/reference/string/stoi/

#include <string>

void main ()
{
    char *lower = "552";
    int e = stoi(lower);
}

答案 1 :(得分:0)

是的,试试sstream!

#include <sstream>
using namespace std;
void main()
{
   sstream s;
   char * lower = "552";
   int i;
   s<<lower;
   s>>i;

}