无符号字符串[关闭]

问题描述 投票:-1回答:3

如何将字符串标识为unsigned char字符串?

例如这样的事情就是我想到的

unsigned char* ucstr = U"\x10\x12\x14\x16";

是否有像我放置的U这样的标识符?或者我必须施展它吗?

c++ c
3个回答
2
投票

user-defined literals是你能得到的最好的。既然不存在就自己做!然后你可以做你的reinterpret_cast来获得正确的类型。

const unsigned char* operator""_u (const char* bytes)
{
   return reinterpret_cast<const unsigned char *>(bytes);
}

0
投票

声明使用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");

0
投票

C有复合文字:

(unsigned char []) { "string" }
© www.soinside.com 2019 - 2024. All rights reserved.