I have an integer 1 and i want to display it as a character ‘1’ in C++. So far I have only managed to convert it from say integer 65 to character ‘A’.
How do you stop this ?
I have an integer 1 and i want to display it as a character
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This works because it’s guaranteed1 that the sequence of characters
'0'…'9'is contiguous, so if you add your number to ‘0’ you get the corresponding character. Obviously this works only for single digits (iftheDigitis e.g. 20 you’ll get an unrelated character), if you need to convert to a string a whole number you’ll needsnprintf(in C) or string streams (in C++).By the way, I suppose that they didn’t mandate contiguity also in the alphabetical characters just because of EBCDIC.