cout print hex instead of decimal

后端 未结 2 1804
时光取名叫无心
时光取名叫无心 2020-12-21 01:46

has it occurred to anyone that a simple std::cout might print a value in hex format when it is supposed to format just a decimal(like an integer)?

for e

相关标签:
2条回答
  • 2020-12-21 02:20

    You probably have set std::cout to print hex in prior in the context of your code but forget to reset. For example:

    std::cout<<std::hex<<12;
    /*blah blah blah*/
    std::cout<<12; //this will print in hex form still
    

    so you have to do like the following

    std::cout<<std::dec<<12;
    

    to print in decimal form.

    0 讨论(0)
  • 2020-12-21 02:43

    Try to find line like this std::cout << std::showbase << std::hex; some where in your code, which sets std::cout to print output in hexadecimal with 0x base indicator prefix. To reset it to show decimal add this line std::cout<<std::dec before the current cout.

    You can learn more about c++ io manipulators flags here

    0 讨论(0)
提交回复
热议问题