自己写atoi

来源:互联网 发布:方舟生存进化帧数优化 编辑:程序博客网 时间:2024/06/03 22:46
#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;}

0 0
原创粉丝点击