Pointer to string with spaces [closed]

Hint: Since you are using C++, look up the hex I/O Manipulator:
http://en.cppreference.com/w/cpp/io/ios_base/fmtflags

If you want to use the C style I/O, look up the printf modifier, %x, as in "0x%02X ".

Edit 1:
To save in a variable, using C style functions:

char hex_buffer[256];
unsigned int i;
for (i = 0; i < size; i++)
{
    snprintf(hex_buffer, sizeof(hex_buffer),
             "%x ", buffer[i]);
}

Using C++, lookup the std::ostringstream:

  std::ostring stream;
  for (unsigned int i = 0; i < size; ++i)
  {
    stream << hex << buffer[i] << " ";
  }
  std::string my_hex_text = stream.str();

Leave a Comment