> I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
> it possible to get this output using std::cout?
> Thanks
> > I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
> > it possible to get this output using std::cout?
[quoted text clipped - 11 lines]
> return 0;
> }
That works, but I prefer to use io manipulators:
#include <iostream>
#include <iomanip>
using std::cout;
using std::setw;
using std::setfill;
using std::ios;
using std::hex;
using std::dec;
int main(int argc, char * const argv[]) {
cout << " 0x" << setw(8) << setfill('0') << hex << 0x14000 << "\n" << dec << 123 << "\n";
return 0;
}
Gregory Weston - 22 Mar 2008 19:49 GMT
> > > I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
> > > it possible to get this output using std::cout?
[quoted text clipped - 30 lines]
> return 0;
> }
Certainly a more elegant solution, but I figured the question was basic
enough that it kind of warranted the most explicit/obvious possible
answer. I've found manipulators confuse people completely new to the
language more than they help right up front.
Can I Get a Word In - 24 Mar 2008 00:04 GMT
>>>> I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
>>>> it possible to get this output using std::cout?
[quoted text clipped - 33 lines]
> answer. I've found manipulators confuse people completely new to the
> language more than they help right up front.
Thanks for the reply. I'm actually comfortable using manipulators, it
just wasn't immediately obvious how to use them to get the output I wanted.
Can I Get a Word In - 24 Mar 2008 00:05 GMT
>>> I have a hex value, 0x14000, and I want to output it as, 0x00014000. Is
>>> it possible to get this output using std::cout?
[quoted text clipped - 28 lines]
> return 0;
> }
Thanks, I got it.