84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
string str ="123456";如何把str的每一位str[i]转换成数字?
已经尝试:用int(str[i])只能得到ascii码。用atoi(str.c_str())也只能将整个string转换成int。
学习是最好的投资!
You have already got the ASCII code, isn’t it just a number after subtracting ‘0’ (that is, 48)...
#include <string> #include <stdlib.h> using namespace std; int main(){ string str = "123456"; const char *p = str.c_str(); for (int i = 0; i < str.length(); i++) { int a = str[i] - '0'; printf("%d \n", a); } system("pause"); return 0; }
You have already got the ASCII code, isn’t it just a number after subtracting ‘0’ (that is, 48)...