Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Quote:
Original post by OneMoreToGo
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.


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

Share this post


Link to post
Share on other sites
Sign in to follow this