#include <iostream>
using namespace std;
const int maxv = (1 << 31) - 1;
const int minv = (1 << 31) ;
int strToInt(const char *str)
{
if(!str)
exit(-1);
char *p = const_cast<char*>(str);
int re = 0;
bool nagetive = false;
if(*p == '-' || '+')
{
if(*p == '-')
nagetive = true;
p++;
}
while(*p)
{
re *= 10;
re += (*p++ - '0');
}
return nagetive ? (0 - re) : re;
}
int main(void)
{
// cout << maxv << endl << minv << endl;
char a[] = "-123456";
cout << strToInt(a) << endl;
return 0;
}
自己写atoi
最新推荐文章于 2022-04-10 10:38:31 发布