Hi all,
How do I display leading zero in single integer like 1-9 becomes 01-09? Are there any function or library to use? Thanks for enlightenments. My compiler Dev- C++ 4.
Printable View
Hi all,
How do I display leading zero in single integer like 1-9 becomes 01-09? Are there any function or library to use? Thanks for enlightenments. My compiler Dev- C++ 4.
How about prefixing a 0 if int / 10 < 1 ?
Code:#include<iostream>
using namespace std;
int main()
{
for ( int i=1;i<15;++i)
cout << ((i<10) ? "0":"") << i <<endl;
return 0;
}
Aahh... easy when you know how, thanks Stone_Coder and Seron for your reply to such a newbie question. Thanks!
..and another solution -
Code:#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setfill('0') << setw(2) << 1;
return 0;
}