字符串转换成整数
1 #include<iostream> 2 using std::cout; 3 4 5 int func(char *s){ 6 if(s==NULL) return -1; 7 8 int num=0; 9 while(*s!='\0'){ 10 num = num*10 + *s - '0';//认真体会这条代码 11 ++s; 12 } 13 14 return num; 15 16 } 17 18 int main(){ 19 // char* m = NULL; 20 char n[] = "123450"; 21 cout<<func(n); 22 return 0; 23 }