自己实现字符串转int

std::string  num = "770756";
int Number = 0;
int x, y;
if (num[0] == '-') {
x = 1;  y = num.length() - 2;
for (; x < num.length(), y >= 0; x++, y--) {
int NewNumber = num[x] - 48;
Number += (NewNumber * pow(10, y));
}
Number = ~(Number - 1);  
}
else {
x = 0;  y = num.length() - 1;
for (; x < num.length(), y >= 0; x++, y--) {
int NewNumber = num[x] - 48;
Number += (NewNumber * pow(10, y));
}

}

    std::cout << Number << std::endl;

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页