Way to get unsigned char into a std::string without reinterpret_cast?

Posted by WilliamKF on Stack Overflow See other posts from Stack Overflow or by WilliamKF
Published on 2010-05-15T16:23:03Z Indexed on 2010/05/15 16:34 UTC
Read the original article Hit count: 220

Filed under:
|
|

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);

© Stack Overflow or respective owner

Related posts about c++

Related posts about reinterpret-cast