================================================================================ File: NotesOnFill.txt (04/05/2010) ================================================================================ One function that you may find useful in your programming efforts is the ".fill()" function. This function is a member of the "ostream" class, so you'll be able to use it with either an ostream object (like "cout") or an ofstream object. The scenario is this: you want to write some data to an output stream, but you want it right-justified within a field width. So, you write something like this: cout << "|" << setw(6) << 1234 << "|" << endl; This will write the integer value 1234 to stdout, right-justified in a field width of 6 characters. The value will consume 4 of the 6 spaces in the field width, which means the first two characters in the field width will be unused. The field width is surrounded by vertical bar characters on either side, so the output looks like this: | 1234| See what gets written to the two unused positions in the field width? That's where the notion of a "fill character" comes into play. A fill character is the character that's used to fill up the unused portion of a field width. The default fill character is a blank space character, so you see two leading blank spaces, followed by the value 1234, between two vertical bars. However, it's possible to specify a different fill character, and that's where the ".fill()" member function is useful. All you have to do is use the output stream object and the dot operator to call the function, and supply a character argument when you make the call. For example: cout.fill('X'); cout << "|" << setw(6) << 1234 << "|" << endl; By executing the ".fill()" function before the "cout" statement, a new fill character is established, and unused space in the field width is filled with that character, so the output looks like this: |XX1234| With the ".fill()" function you'll be able to set the fill character to lowercase 'x' characters, leading zeros, dot characters, anything you wish. Try it out!