Q:

How to convert an int to ASCII char C++

I have to convert an int to an ASCII string.
Basically, i want this :
    int iTest = 128;
    char ca[3];
??? --> **SOLUTION :** sprintf(ca,"%d",iTest);

and the result :
 ca[0] = 0x31;--> Hexcode of '1'
 ca[1] = 0x32;
 ca[2] = 0x38;

A:

Use std::string and std::to_string :
#include <string>
#include <iostream>

using namespace std;

...

int iTest = 128;

string ca = to_string(iTest);

for (int i = 0; i < ca.size(); i++)
{
    cout << hex << "0x" << (int) ca[i] << endl;
}

Result:
0x31
0x32
0x38

