staticint string2Int(const string& source)
{
int digits = 0;
istringstream instr;
string cleandigits = getDigits(source); //Here I just remove all the non digit characters
instr.str(cleandigits);
instr >> digits;
return digits;
}
The problem is that if lets say I have an input in the source like 0123 45678 it works great but if the input is something like 01234 1234567 it returns zero. Obviuslly there is a limit with the size but I tried to change the digits from int to double or long int but is not that the problem. Any idea what is going wrong?
Also if I put a breakpoint before the instr.str(cleandigits); command the variable cleandigits contains the number e.x 012341234567 but after the shifting the digits becomes 0.
I am not really familiar with this object, but rather than return an incorrect result, it probably does not alter the passed in variable (digits), and sets the failbit. Check the return of the operator to see if it succeeded. As to why it's failing, pretty sure it's just because an int can't hold a number that large on most systems (on 32 bit systems, a signed integer can hold up to 2^31, or ~2 billion)