Reputation: 185
char
takes values in the range of -128 to 127. By simply putting unsigned
before char
the range changes to 0-255.
How to achieve the same effect in a string
? So that all char
s in that string take values from 0-255?
Upvotes: 0
Views: 1084
Reputation: 15089
char
takes values in the range of -128 to 127.
No.
char
is implementation-defined, it could be either signed char
or unsigned char
depending on what your compiler chose to use. And char
doesn't necessarily means byte
BTW... (there are some platforms where a char
is 16 bits for example)
If you want to ensure that a char
is indeed an unsigned char
then just cast it: static_cast<unsigned char>(some_char_value)
Upvotes: 1