close
Convert string (char array) to int.
#include <iostream> #include <cmath> using namespace std; int a2i(char* s) { int n = 0; while ((*s)!='\0') n=n*10+ ( (*s++)-'0' ); return n; } int main() { char s[6] = "12345"; int a = a2i( & s[0] ); cout << a; return 0; }
全站熱搜