The fill
function is another way of changing the fill character. Its effect is the
same as the setfill
manipulator.
#include <iostream> #include <iomanip> using namespace std; int main() { cout << "|" << setw(20) << 123.45 << "|" << endl; cout << endl; cout.fill('0'); cout << "|" << setw(20) << 123.45 << "|" << endl; cout << "|" << left << setw(20) << 123.45 << "|" << endl; cout << "|" << right << setw(20) << 123.45 << "|" << endl; cout << endl; cout << "|" << setw(20) << 123.45 << "|" << endl; cout << endl; cout.fill('0'); cout << "|" << setw(20) << 123.45 << "|" << endl; return 0; }
Output:
| 123.45| |00000000000000123.45| |123.4500000000000000| |00000000000000123.45| |00000000000000123.45| | 123.45|