printing hex values

D

David Rubin

This is totally lame...How do I use iomanip's to get the equivalent of

printf("%#.8x", 0xabcd);

which should yield

0x0000abcd

I tried

std::cout << std::setprecision(8) << std::hex << std::showbase <<
0xabcd;

to no avail.

/david
 
M

Mike Wahler

David Rubin said:
This is totally lame...How do I use iomanip's to get the equivalent of

printf("%#.8x", 0xabcd);

which should yield

0x0000abcd

I tried

std::cout << std::setprecision(8) << std::hex << std::showbase <<
0xabcd;

#include <ios>
#include <iomanip>
#include <iostream>

int main()
{
std::cout << std::hex << std::showbase
<< std::setw(10) << std::setfill('0')
<< std::internal
<< 0xabcd << '\n';

return 0;
}

HTH,
-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top