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
Printable View
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
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;
}