I was recently making a program which needed to check the number of digits in a number inputted by the user. As a result I made the following code:
int x;
You could read the user input as a string, and then count the characters? (After sanitising and trimming, etc.)
Alternatively, you could get a library to do the hard work for you; convert the value back to a string, and then count the characters:
cin >> x;
stringstream ss;
ss << x;
int len = ss.str().length();