I would like to store an integer to a character array and then display the character (which would be an alpha numeric at that point?). I tried casting to char, but it just changes the integer into some strange character symbol. What can be done?
That is an interesting approach. I was hoping that by now someone had created a function in the C++ library to do all those low-level programming routines based on a few arguments sent to its parameters. As it turns out, I kept surfing the net and found the itoa() function. It functions quite well and seems to be located in #include <cstdlib>.
An example of its use would be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
int val =10;
char chaval[3] = {{'A'},{'B'},{'C'}};
cout << chaval << "\n";
itoa(val, chaval, 10);
cout << chaval;
return 0;
}
to_string sounds excellent. However not all compilers (even those which implement some C++11 features) support it. I don't think itoa is a standardised function, so it may not be available.