Archived

This topic is now archived and is closed to further replies.

Convert a char to an integer

This topic is 5804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

How do I convert a char to an integer?

Share on other sites
int i = static_cast<int>(''a'');

Forever trusting who we are
And nothing else matters
- Metallica

Share on other sites
That''s possibly not so readable to a newbie.

int i = 1;
char c = 2;

i = (int) c;

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share on other sites
You don''t need to convert a char to an integer - it''s an implicit promotion. Do you mean something else?

Share on other sites
wwhat that guy was doing is typecasting, but i dont understand what the first guy was doing.
is that STL?

<marquee width=100% direction=right><table nostyle="filter:glow(color=red,strength=3)"><table nostyle="filter:shadow(color=blue,direction=left)">Can someone be nice and help me on my way to be the next Hideo Kojima?</table></table></marquee>

Share on other sites
quote:
Original post by Pipo DeClown
wwhat that guy was doing is typecasting, but i dont understand what the first guy was doing.

That is typecasting as well.
quote:

is that STL?

No, it''s standard C++.

Share on other sites
Go IndirectX!

<marquee width=100% direction=right><table nostyle="filter:glow(color=red,strength=3)"><table nostyle="filter:shadow(color=blue,direction=left)">Can someone be nice and help me on my way to be the next Hideo Kojima?</table></table></marquee>

Share on other sites
the guy was probably asking how to parse an int from a char* used as a string.

Share on other sites
if it is just a single char that is a number and you want an int to be equal to that number

  char c = ''5'';int num = c - ''0'';

num is now equal to 5

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share on other sites
If it''s a string you probably want to use atoi.

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

• 10
• 15
• 14
• 18
• 15