从字符串'99'(或小于100的任何其他数字)传递到int 99时没有问题。但是,当我尝试大于99的数字时,它给出了(数字-1)。我也发现这种情况发生在数字小于1000的情况下,但是从1000到10000没关系,但是我测试了大于10 ^ 4的数字,这又给了(数字-1)。这是我的转换字符串的代码
//Search how many nums are in the string wer are passing until an space or new line
int nums = 0;
for(int j = i; j < s.size(); j++){
if(s[j] == ' ' || s[j] == '\n') break;
nums++;
}
//pass to the variable time the string character by character
int time = 0;
while(nums--){
time += (s[i] - '0') * (pow(10, nums));
i++;
}
我想知道我的计算机是否有错误或我丢失了什么。