c++ - Unsigned string construction impossible -
i looking way string of unsigned chars. stumbled upon strings of unsigned chars
so answer create new typedef follows :
typedef std::basic_string<unsigned char> ustring;
the thing is, i'm not able construct this. when try :
char *p = "123123"; auto s = ustring(p);
i following error :
no instance of constructor "std::basic_string<_elem, _traits, _alloc>::basic_string [with _elem=unsigned char, _traits=std::char_traits<unsigned char>, _alloc=std::allocator<unsigned char>]" matches argument list
can please shed light on issue?
thanks in advance!
irrespective of whether or not char
signed
or unsigned
on platform, char
, unsigned char
, , signed char
all distinct types. rather int
, long
distinct types if have same number of bits , complement scheme.
so you'd have better luck with
const unsigned char* p = (const unsigned char*)"123123";
where i've inserted const
qualification emphasise read-only nature of const char[7]
literal.
Comments
Post a Comment