Wecan use the
width() function todefine the width of a field necessary for the output of an item. Since, it is a
member function; we have to use an object to invoke it, as shown below:
Wherew is the field width (number of columns). The output will be printed in a field
of w characters wide at the right end of the field. The
width() function can specify the field width for only one item (theitem that follows immediately). After printing one item (as per the
specifications) it will revert back to the default. For example, The statements
cout.width(5);
cout