How can i get a preceding 0 in one digit numbers?
Going to use it in a clock...
I know there is a function that can do this...
How can i get a preceding 0 in one digit numbers?
Going to use it in a clock...
I know there is a function that can do this...
[Signature here. (Remove this!)]
If it's just for output you can take your pick between these two -
If you want to store the number with a preceding zero as a character then you can use stringstream or sprintf.Code:#include <iostream> #include <iomanip> #include <cstdio> using namespace std; int main() { int i =5; cout <<setfill('0')<<setw(2)<< i << endl; printf("%02d\n",i); return 0; }
Thanks a lot!
Just what I was looking for
[Signature here. (Remove this!)]