我想将命令行char * argv []参数转换为int。我正在学习OpenCV,它就像这样使用:
int main(int argc, char* argv[])
{
int divideWith = 0;
stringstream s;
s << argv[2];
s >> divideWith; //This is my argument converted to int
}
它使用了一个stringstream类。有没有其他方法将字符串(char数组)转换为int。我已经知道这样做了:
char a = '7';
int b = a;
在这里,它将ASCII表示符分配给我的int变量。我希望它是这样的:
char a = '7';
int b = somefunction(a); //A function, algorith or what ever that returns an int '7'
cout << b;
这应该给我7个结果在命令行。