By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,388 Members | 1,822 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,388 IT Pros & Developers. It's quick & easy.

how to display 1 as 01?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
thanks!

Jul 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.