I'm looking a way to convert an integer for example 50, to its ASCII as string.
So far, I tried casting integer to char with
int a = 57 ;
char c = char(a);
But I couldnt convert that char into string. Looking forward to your help!
I'm looking a way to convert an integer for example 50, to its ASCII as string.
So far, I tried casting integer to char with
int a = 57 ;
char c = char(a);
But I couldnt convert that char into string. Looking forward to your help!
http://en.cppreference.com/w/cpp/string/basic_string/basic_string
int a = 50;
std::string s(1, char(a));
Using the "fill" constructor (2).
A string is a squence of char and 0 at end.
int a = 57 ;
char c[2] = { (char)a, 0 };
-
#include <string>
std::string str;
str += (char)a;
I don't get your question..the value of int
is already the ASCII value.
In your example, 57 is the ASCII value for character 9. Then you can't convert that character to integer where in fact you were the one that declared its value.
If you want character to its ASCII value:
char b;
cin>>b;
int a = int (b);