Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c++ - cout print hex instead of decimal

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...