You just needed to cast the unsigned char
into a char
as the string
class doesn't have a constructor that accepts unsigned char
:
unsigned char* uc;
std::string s( reinterpret_cast< char const* >(uc) ) ;
However, you will need to use the length argument in the constructor if your byte array contains nulls, as if you don't, only part of the array will end up in the string (the array up to the first null)
size_t len;
unsigned char* uc;
std::string s( reinterpret_cast<char const*>(uc), len ) ;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…