How do i write the following function with cout? My main purpose is to actually print all the values to a file after i know how to use it with cout. std::hex does not work!
void print_hex(unsigned char *bs, unsigned int n)
{
int i;
for (i = 0; i < n; i++)
{
printf("%02x", bs[i]);
//Below does not work
//std::cout << std::hex << bs[i];
}
}
edit:
cout print out values such as : r9{èZ[¶ôÃ
I think adding a cast to int will do what you want:
This is needed to force it to print as a number, not a character which is what you were seeing.