Why is std::cout not printing the correct value for my int8_t number?

前端 未结 4 1724
北海茫月
北海茫月 2020-11-28 14:47

I have something like:

int8_t value;
value = -27;

std::cout << value << std::endl;

When I run my program I get a wrong random

4条回答
  •  一整个雨季
    2020-11-28 15:12

    It looks like it is printing out the value as a character - If you use 'char value;' instead, it prints the same thing. int8_t is from the C standard library, so it may be that cout is not prepared for it(or it is just typedefd to char).

提交回复
热议问题