Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
char取 -128 到 127 范围内的值。只需在范围更改为 0-255unsigned之前放置。char如何在 a 中达到相同的效果string?那么该char字符串中的所有 s 都取 0-255 之间的值?
char
unsigned
string
char取值范围为 -128 到 127。
不。
char是实现定义的,它可以是signed char或者unsigned char取决于您的编译器选择使用什么。char并不一定意味着顺便说byte一句......(例如,有些平台 achar是 16 位)
signed char
unsigned char
byte
如果您想确保 achar确实是 anunsigned char然后只需转换它:static_cast<unsigned char>(some_char_value)
static_cast<unsigned char>(some_char_value)