468,456 Members | 1,780 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

how to display 1 as 01?

hi!

i have an integer with a value of, say, 2 and want it to look like 02
or, for a date class, 0002 (like e.g. 02-02-2006)

please help!

Jul 4 '06 #1
3 12308
Hi ,

use
printf("%02d", num)
or
printf("%04d",num);

Regards,
Mukil

Erich Pul wrote:
hi!

i have an integer with a value of, say, 2 and want it to look like 02
or, for a date class, 0002 (like e.g. 02-02-2006)

please help!
Jul 4 '06 #2
TB
Erich Pul skrev:
hi!

i have an integer with a value of, say, 2 and want it to look like 02
or, for a date class, 0002 (like e.g. 02-02-2006)

please help!
#include <ostream>
#include <iomanip>

int a = 2;
int b = 10;

std::cout << std::setw(2) << std::setfill('0') << a;
std::cout << std::setw(2) << std::setfill('0') << b;
--
TB @ SWEDEN
Jul 4 '06 #3
thanks!

Jul 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by Mat | last post: by
3 posts views Thread by shreddie | last post: by
7 posts views Thread by Stefan Finzel | last post: by
reply views Thread by Ferry Boender | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.