0

How do I return the ASCII value of a char variable?

I understand that char stores a single character as an ASCII value. Is there an easy way in C++ to return the ASCII value of a char variable instead of the letter itself, as in: main() char someLetter; cout << "Enter a letter--> "; cin someLetter; cout << "The ASCII value of the letter you typed is " << ???; return(0);

2nd Jan 2017, 10:01 AM
Jeffrey Cheeseman
4 Answers
+ 2
char c; cin>>c; cout<<static_cast<int>(c);
2nd Jan 2017, 10:04 AM
Roman GrÀf
Roman GrÀf - avatar
+ 2
Don't works for Unicode i think but they arent ascii
2nd Jan 2017, 10:12 AM
Roman GrÀf
Roman GrÀf - avatar
0
Excellant! Exactly what I was looking for, thank you.
2nd Jan 2017, 10:10 AM
Jeffrey Cheeseman
0
Can char hold non-ascii unicode characters?
2nd Jan 2017, 10:15 AM
Jeffrey Cheeseman