The problem is the << operator.
This is really a function call so something like:
-
ostream& operator<<(ostream& os, char);
-
This function is programmed to display the letter and not the numeric value of the char.
Do this instead:
-
char c = 'A';
-
int temp = c;
-
cout << temp;
-
Now the << operator is a call to this function:
CODE]
ostream& operator<<(ostream& os, int);
[/code]
This function is programmed to show the numeric value of the int.
Remember, the << operator means FORMATTED OUTPUT. The formatting is accomplished by an appropriate overload of the << operator.
Avoid printf(). This function cannot be used to output to anythign other than the screen. AND is only works with the buiklt-in types of C. However, a << function will output to whereever the os object says to. That means without changing your code you can output to the screen, the disc, or maybe even send a packet across a network.