如何将字符串标识为unsigned char字符串?
例如这样的事情就是我想到的
unsigned char* ucstr = U"\x10\x12\x14\x16";
是否有像我放置的U
这样的标识符?或者我必须施展它吗?
user-defined literals是你能得到的最好的。既然不存在就自己做!然后你可以做你的reinterpret_cast
来获得正确的类型。
const unsigned char* operator""_u (const char* bytes)
{
return reinterpret_cast<const unsigned char *>(bytes);
}
声明使用unsigned char
字符的字符串文字没有前缀。只需使用普通的基于char
的字符串文字并输入指向它的指针,例如:
const unsigned char * ucstr = (const unsigned char *) "\x10\x12\x14\x16";
要么
const unsigned char * ucstr = reinterpret_cast<const unsigned char *>("\x10\x12\x14\x16");
C有复合文字:
(unsigned char []) { "string" }