문제

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 chars in that string take values from 0-255?

도움이 되었습니까?

해결책

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top