I have an unsigned char array that I need in a std::string, but my current way uses reinterpret_cast which I would like to avoid. Is there a cleaner way to do this?
unsigned char my_txt[] = { 0x52, 0x5f, 0x73, 0x68, 0x7e, 0x29, 0x33, 0x74, 0x74, 0x73, 0x72, 0x55 } unsigned int my_txt_len = 12; std::string my_std_string(reinterpret_cast<const char *>(my_txt), my_txt_len);
reinterpret_cast...?charformy_txt; after all, those values you posted are ASCii. This may lead to solving other issues.stringfromunsigned char*seems pretty reasonable to me. I'm surprised anyone has an objection to wanting to do that without using a cast.