Couldn't you do something like "num = (int)character;"?
Couldn't you do something like "num = (int)character;"?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
He actually meant a string (char array), not a single character.Originally posted by Hunter2
Couldn't you do something like "num = (int)character;"?
Plus, that won't work so good since 5 != '5'
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Well, look at the code example above. That's not a char array! And I'm not sure what static_cast<int> does, but I'm pretty sure it's the same thing as (int) - (int) is typecasting, and static_cast is... well, staticcasting I guess What's the difference?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
The original poster used cin.getline() to read the input, and that returns a char array, not a character.Originally posted by Hunter2
Well, look at the code example above. That's not a char array!
Using int = (int)char can only convert a number in the range 0-9, plus it wouldn't display right without some extra modification. Try to print out (int)'1' and you'll see why.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Sorry, I might have misunderstood... (int) converts it to the integer value of the ascii character?
Sorry, I don't follow you very well...Using int = (int)char can only convert a number in the range 0-9, plus it wouldn't display right without some extra modification.
Doesn't it print out the int value of the ascii character like it should? (i.e. 97 or something)Code:char character = 'a'; int n = (int)character; //no error here! std::cout << n;
P.S.
I wasn't replying to the original poster; I was replying to Troll_King. I merely suggested the use of (int)character instead of static_cast<int>(character). I never said that I was right that it was/did the same thing, I simply made a statement that it looked the same to me.
P.P.S.
the code above (i.e. Troll_King's code) has nothing to do with the original poster's code. Did you not read my post before hitting reply?Well, look at the code example above. That's not a char array!
Last edited by Hunter2; 10-17-2002 at 04:40 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.