Hello, I have a 4-digit integer which sometimes, for example, will be envede, sometimes it will have zeros to its left, but the problem is that I don't know how to show the zeros to the left, suppose I have the following integer:
0382
How could I do to show it with a cout or a printf the zeros on its left since my number for example will be four characters. Or sometimes it will have more zero as I will be able to show the leading zeros. In my attempt I will make a cout:
int i;
i=0382;
cout << i;
But it will show me as 382 how could I do to show these zeros?
You can use
printf
instead ofcout
.includes the library
iomanip
Putting 0 in an integer is useless because they are ignored... Zeros are added when printing the value
You can make use of
cout.fill
andcout.width
.ideoneTest