Displaying Numbers

Can some one tell me how to get a number to display with a zero before it, eg 5 to be displayed as 05 or 20 to display as 020.

I want to use it as in minutes and seconds display.

Not character literals.

Thanks guys.
I don't know if this is what you want, but maybe...

cout << "0" << myNumber << endl;

Assuming the "5" and "20" is a variable.
Actually, the number could be any variable. . .but if it happens to result in a normally single digit number and I want it displayed to 2 places on the left side of the decimla point.

Eg. . .I write a program that lets the user enter a number, the program will output the answer in minutes and seconds. . . so no matter what number the user puts in the display should show mm:ss. . . .where m=minutes and s= seconds. . .

If the user inputs 3 then the display should be 00:03 seconds alternatively if the user puts in 67 then the output should be 01:07 . . . .

Thanks
You mean something like this?
printf("%02d",var);
(No way I'm going to write that in iostreams.)

As for the sexagesimal display, you'll have to write that code yourself. It's not that hard, just a little fooling around with modulo and integral division.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;
using std::setfill;


int main()
{
int number;
cout<<"Enter a number: ";
cin>>number;
cout<<endl<<"The number entered is: " <<setfill('0')<<setw(2)<<number;
return 0;
}
Thanks. . .helios for the food for thought. . .I never thought of the sexagesimal path but maybe. . .

I used raahulcrjk's suggestion and it works so thanks everyone. .
Gee - I don't even know how that works. I just can't seem the understand past the extreme basics -_-
Topic archived. No new replies allowed.