I was just wondering, what would be the best way of converting a char variable (made up of numbers only, up to three digits) into an int variable. Help appreiciated
Printable View
I was just wondering, what would be the best way of converting a char variable (made up of numbers only, up to three digits) into an int variable. Help appreiciated
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Hint:
Also see isdigit().Code:char c;
int x;
x = c - '0';
A char variable can only hold a single digit. You probably mean a string (or a character array used to store a string).
Use a stringstream (as in the first FAQ linked) or boost::lexical_cast.
This http://cboard.cprogramming.com/showp...32&postcount=7 works nicely. I seem to reference this a lot ;)