Sign in to follow this  
OneMoreToGo

Converting int value to ASCII letter

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this