previous | start | next

How to ... : 1

How can you print the headings:

        Description       Qty       Price       Total
     

so that

  1. include <iomanip>
  2. Use cout << setw(25) to cause the next item output be in a field of 25 character positions
  3. cout.setf(ios::left, ios::adjustfield) causes an item that needs fewer character positions than the field to be placed in the left most positions (and padded with the fill character, i.e., blanks)
  4. cout.setf(ios::right, ios::adjustfield) causes an item that needs fewer character positions than the field to be placed in the right most positions (and padded with the fill character, i.e., blanks)
cout.setf(ios::left, ios::adjustfield);
cout << setw(15) << "Description";
cout.setf(ios::right, ios::adjustfield);
cout << setw(10) << "Qty"
     << setw(10) << "Price"
     << setw(10) << "Total" << endl;


previous | start | next