471,075 Members | 969 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

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 13876
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.