The conversion you did is C, what I offered you is C++. The advantage here is that you don't have to care what type x has. As long as the operator>> for x is defined and implemented (and it's for all native types), you can do the conversion with no problems.
Alternatively, for digits, you can use the ASCII codes. A char is actually just a number interpreted through the ASCII table. By looking at the table, you can find that '0' is 48, '1' 49 and so on until '9' as 57. As a result, you can do this:
char a = '6';
int b = a-48;
b now holds 6 (the value), while a holds '6' (the character).