Behavior of cout << hex with uint8 and uint16

后端 未结 3 1569
刺人心
刺人心 2021-02-15 00:19

I\'m noticing that cout << hex is giving me strange results, and I cannot find anywhere that answers why. What I am doing is simply assigning some values to

3条回答
  •  花落未央
    2021-02-15 00:29

    The other answers are correct about the reason. The simplest fix is:

    cout << hex << +a << endl;
    

    Demonstration: http://ideone.com/ZHHAHX

    It works because operands undergo integer promotion.

提交回复
热议问题