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.
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; }
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
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; }