if you want to count the leading 0 too, you must read it in as a string.
that is because, when you enter 0123 it will actualy be 123, as you correctly noticed.
Just like we do.. or do you write 123 as 0123 when doing calculations on paper? ;)
You can read it as a string and convert it to a number when you need to. However, you gotta realize that integers are values, not rows of digits. 0123 and 123 have the same value, and it's the value that's being saved to an integer.
no, i meant it in general. i dont know anybody who wirtes an 0 in front of numbers when doing calculations anywhere.
but back to your question, that is why cin will not give you an int/long int/whatever with a leading 0. it will just ignore it.
so no, there is no other way. because cin ignores the leading 0, there is no way you can find out if the input was 123, 0123, 00000000123 and so on when dealing with numerical types.
only strings, char arrays and such things will help you.
but whats wrong with using strings? a simple .size(); and you have the number of digits. ok maybe you have to check if any thing of the input is no number.
but entering something like "1abc" in your code above will result to number = 1.
so make it a little search, eventualy extract a substring and size and you are done.