This is the most likely cause.
As far as I know, the only two things that can (legally)
affect the formatting via any stream are passing a manipulator
to them (such as hex) or explicitly changing their flags.
The only thing which affects the output of an int are the
different formatting parameters in ios_base: the flags, the fill
character and the width. (For some reason, C++ doesn't use the
precision field, although C does.) These flags can only be
manipulated by member functions. Manipulators call these member
functions.
By convention, inserters (operator<<) which use the width field
should reset it to 0, and change no other formatting parameters
(so fields like precision or the flags are sticky). This is
just a convention, however, and a rogue operator<< can change
things it's not supposed to. (That is, after all, how
manipulators work.)
Neither printf nor any environmental variable should affect
such formatting at all.
My pick is that some call to some external library is directly
affecting cout.
You can check out cout's flags after those calls to find the
offending call (adding a "cout << dec;" after that particular
call, to solve the problem) otherwise you can explicitly put
cout in decimal mode every time before outputting your ints -
which should be the correct habit: never make assumptions on
the current state of a shared resource, either check it or set
it to the state you want it to be.
The "Internet principle" holds: be liberal in what you accept,
and conservative in what you send. Always restore the state
when you're finished, and never count on it being anything
specific.