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; }

 

 

arrow
arrow
    全站熱搜

    Cuby 56 發表在 痞客邦 留言(0) 人氣()