__int64 m_atoi(const char* str)
{
if (!str) return 0;
__int64 res = 0; //设置成__int64防止溢出
__int64 sign = 1;
const char* p = str;
while (*p == ' ' || *p == '\t') ++p; //字符串前面的空格
if (*p == '-'){ //正负号
sign = -1;
++p;
}
else if (*p == '+'){
++p;
}
while (*p){
if (*p >= '0' && *p <= '9'){
res *= 10;
res += (*p - '0');
}
else if (*p != ' ' && *p != '\t'){ //若遇到空格或制表符以外的字符,则返回错误
return 0;
}
++p;
}
return res*sign;
}