Hi, I would like to know if there's a way to show at least two numbers in the output instead of just one.
For example: instead of showing 4 it shows 04.
Its for a console application.
int x = 4;
cout << setfill('0') << setw(2) << x; --> prints 04
cout << setfill('0') << setw(4) << x; --> prints 0004
cout << setfill('$') << setw(4) << x; --> prints $$$4
1. the setfill() will set what should be used as filler in case the value to be printed has lesser length compared to the set width. In this case, setfill('0') will set 0 as filler.
2. the setw() will set the width of the value to be printed. In this case, setw(2) means reserve a minimum of 2 character as a place value where to print the value to be printed.