Conversion of char to int?

I want to convert a char '1' and convert to and int 1. Is there any way to do this?(I already know that char can be converted to integers, but I don't want something from the ascii table).
Use itoa(), sprintf() if you use C, or std::stringstream or boost::lexical_cast if you want a C++ solution.
Just subtract ASCII '0' from it.

1
2
3
int rslt;
char a = '1';
rslt = a - '0';

Will work for any value of a from '0' to '9'.
Assumes you've range checked your input.
Topic archived. No new replies allowed.