The "fill character" is used to fill up the field to the specified width. By default, these characters are added to the left, such that the output will be right aligned. You can use std::left
for left alignment. For numbers, the additional option std::internal
will fill the space between the sign and the actual digits:
cout << setw(5) << setfill('0') << internal << -42 << endl;