If you need to remember the number of leading zeros from the input and print it with exactly the same number of leading zeros later, the only option is not storing as an int
. You could, for example, turn your vector<int>
into a vector<string>
.
Alternatively, you could use a vector< pair<int,string> >
, which keeps the integer you want along with the original string representation.
Finally, if you don't care about the actual number of leading zeros that were in the input, but simply want everything to be padded with leading zeros to equal length, you can use setfill
and setw
:
cout << setfill('0') << setw(5) << 25;