First of all i have an array like this :
unsigned char testArray[4]={0x00,0x10,0x20,0x00};
It should be the input of the following method:
void ReadArray(unsigned char * input)
{
std::string str( input, input + sizeof input / sizeof input[0]);
std::cout << str << std::endl;
}
I am looking for a way to get a string like: 00102000 according to this example.
Using
for (int i =0; i < str.size(); i++)
{
cout << str[i];
}
i am not even able to display those values.
I am usually a C# guy and i am a bit lost here. A hint would be nice.
Update
This is a working version:
void Read(unsigned char * input)
{
std::string str( input, input + sizeof input / sizeof input[0] );
std::stringstream ss;
for (int i =0; i < str.size(); i++)
{
ss << std::hex << (int)str[i];
std::string mystr = ss.str();
if (mystr.size() == 1)
mystr = "0" + mystr;
cout <<mystr;
ss.str("");
}
}
Result