cout print十六进制而不是十进制 [英] cout print hex instead of decimal
问题描述
有人发现一个简单的 std :: cout
可能打印一个十六进制格式的值,当它应该格式化一个十进制(如整数)?
例如,我有一行如下:
std :: cout << _Agent [<目标<< ]仍然是
,在< ((target-> currWorker) - > getEntities()。size())<< entities
of worker [< target-> currWorker< ]<< std :: endl;
可打印:
_Agent [0x2c6d530]仍在 0x1 工人实体[0x2c520f0]
1 - 所述输出是有时十进制,有时候是十六进制
2-行为是smae如果我将((target-> currWorker) - > getEntities()。size())
更改为 ; currWorker) - > getEntities()。size())
所有提示?
$ b b
感谢
您可能已经在代码的上下文中设置std :: cout在先前打印十六进制,忘记复位。例如:
std :: cout<< std :: hex<
/ * blah blah blah * /
std :: cout<<< 12; //这将以十六进制格式打印仍然
,所以你必须像下面这样
std :: cout<< std :: dec<<
以小数形式打印。
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 example, I have a line as :
std::cout << "_Agent [" << target << "] is still among " << ((target->currWorker)->getEntities().size()) << " entities of worker[" << target->currWorker << "]" << std::endl;
which would print :
_Agent [0x2c6d530] is still among 0x1 entities of worker[0x2c520f0]
Note:
1-the said out put is sometime decimal and some times hex
2- the behaviour is smae even if I change ((target->currWorker)->getEntities().size())
to (int)((target->currWorker)->getEntities().size())
any hints?
thanks
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.
这篇关于cout print十六进制而不是十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!