Converting int value to ASCII letter

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

Recommended Posts

I know it's possible to convert an int value to it's corresponding ascii letter. I've googled a bit, but it's not really too clear how exactly it should be done. I know, thanks to the nice people here, that 48 = A (or maybe it's 49 :p ). But how do I output it as a char? I don't think that this would work: char hello[] = {4, 8}; cout << hello << endl; Thanks for any help or suggestions you guys have hidden up your sleaves.

Share on other sites
int A = 41;
std::cout << (char)(A) << std::endl;

http://www.lookuptables.com/

Share on other sites
Quote:
 Original post by OneMoreToGoI know it's possible to convert an int value to it's corresponding ascii letter. I've googled a bit, but it's not really too clear how exactly it should be done. I know, thanks to the nice people here, that 48 = A (or maybe it's 49 :p ). But how do I output it as a char? I don't think that this would work:char hello[] = {4, 8};cout << hello << endl;Thanks for any help or suggestions you guys have hidden up your sleaves.

char hello[] = {68, 65, 72, 72, 75, 0};cout << hello << endl; // Outputs "hello"cout << (char)68 << endl; // Outputs "h"

Internally, chars are ints. They're just 1 byte instead of 4 (usually)

EDIT: Too slow