Is there a way to include a leading zero on a single digit int using cout without using if statements?
edit: nevermind, if statements are sufficiently easy
Is there a way to include a leading zero on a single digit int using cout without using if statements?
edit: nevermind, if statements are sufficiently easy
Last edited by confuted; 07-31-2003 at 03:29 PM.
Away.
In case you still wanted to know, the printf statement can do what you want. You'd have to specify the precision ( I believe it is .#, that is, a period followed by a number). In the case of integers it will force the output to have a specific minimum number of digits and print leading zeros if necessary. I found that info on the following page:
http://www-rocq.inria.fr/scilab/doc/...u-html420.html
~SK
Code:#include <iostream> #include <iomanip> using namespace std; int main(void) { int a = 3; cout << setw(2) << setfill('0') << a << endl; return 0; }