cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Conversion of char to int?
Conversion of char to int?
Aug 5, 2012 at 6:03pm UTC
AlitCandle
(175)
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).
Aug 5, 2012 at 6:13pm UTC
modoran
(2077)
Use itoa(), sprintf() if you use C, or std::stringstream or boost::lexical_cast if you want a C++ solution.
Aug 5, 2012 at 6:14pm UTC
AbstractionAnon
(6954)
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.