0

I am in the midst of debugging someone's code, and I have code like

int i = their_val;
std::cout << "output: " << i << std::endl;

When I look at the log output I see lines like

output: a

Should this happen? Is something changing the cout formatting or could it be something odder?

invisiblerhino
  • 840
  • 1
  • 10
  • 18
  • 1
    "causing integers to become hex numbers" is a phrase to think about... those poor integers. – Kerrek SB Oct 31 '11 at 17:25
  • As the answers below have noted, a preceding `std::hex` is causing the issue. See this previous discussion: http://stackoverflow.com/questions/1532640/which-iomanip-manipulators-are-sticky – Gnawme Oct 31 '11 at 18:20

3 Answers3

3

Did someone cout << std::hex prior to that output? It would cause it to print in hexadecimal.

Michael Kristofik
  • 34,290
  • 15
  • 75
  • 125
  • I think it's probably that (upvoted) but it's a huge enough code base that I can't immediately find it. I realised this was probably the case just after submitting... – invisiblerhino Oct 31 '11 at 17:27
3

Check and see if std::hex gets passed into std::cout anywhere. That would result in the behavior you're seeing.

You can force things to be in decimal using:

std::cout << "output: " << std::dec << i << std::endl;
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
0

You probably did std::cout << std::hex somewhere earlier. You can undo this with std::cout << std::dec.

std::cout << "output: " << std::dec << i << std::endl;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490