title: Formatting output (inputted by the user) in columns
body: <p>I am working on a shopping cart project, and I want to print out the user input like the following output. I don't know how to use setW and right/left keywords, when it comes to the user decides what the output is going to be like. So when they enter different inputs in length, for example setW(20) does not work for them all. </p>
  
  <pre><code>Here is your order:
  ----------------------------------------------------------------
  Name                     Unit_Price                  Quantity
  T-shirt                    $19.99                       2
  
  Sweater                    $39.99                       1
  
  iphone_case                $25.5                        3
  
  Towel                      $9.99                        5
  
  The total charge is $206.42
  ----------------------------------------------------------------
  </code></pre>
  
  <p>This is the display function:</p>
  
  <pre><code>ostream&amp; operator &lt;&lt;(ostream&amp; os, Item&amp; source) {
      os &lt;&lt; source.getName() &lt;&lt; setw(18)
         &lt;&lt; source.getPrice() &lt;&lt; setw(20) &lt;&lt; source.getQuantity() &lt;&lt; endl;
      return os;
  }
  </code></pre>
  
  <p>And this is the output I get with this:</p>
  
  <pre><code>Here is your order:
  ----------------------------------------
  NAME             PRICE            QUANTITY
  tshirt           19.99               2
  sweater           39.99               1
  iphone_case            25.5               3
  towel            9.99               5
  
  The total price of the order is 206.42
  ----------------------------------------
  </code></pre>
  
  <p>And here is my main.cpp</p>
  
  <pre><code>#include "ShoppingCart.h"
  #include "Item.h"
  
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  
      using namespace std;
  
  
      int main()
      {
          cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Welcome to XXX SHOPPING CENTER" &lt;&lt; endl;
  
          Item items[10];
          ShoppingCart&lt;Item&gt; cart;
          char userAnswer;
  
          cout &lt;&lt; "Enter the item you selected as the following order:\nname unitPrice quantity\n"
               &lt;&lt; "(Name can not contain any space. Otherwise errors happen!)" &lt;&lt; endl;
          cin &gt;&gt; items[0];
          cart.add(items[0]);
  
          cout &lt;&lt; "Want to continue? y/n" &lt;&lt; endl;
          cin &gt;&gt; userAnswer;
  
          int index = 1;
          while(userAnswer == 'y' || userAnswer == 'Y') {
  
              cout &lt;&lt; "Enter the next item:" &lt;&lt; endl;
              cin &gt;&gt; items[index];
              cart.add(items[index]);
              cout &lt;&lt; "Want to continue? y/n" &lt;&lt; endl;
              cin &gt;&gt; userAnswer;
              index++;
          }
  
  
          // Display the summary of the orders
          cout &lt;&lt; endl &lt;&lt; "Here is your order:" &lt;&lt; endl;
          // "--------------------------------------------------------------------"
          for(int i=0; i &lt; 40; i++)
              cout &lt;&lt; "-";
  
          cout &lt;&lt; endl &lt;&lt; "NAME" &lt;&lt; setw(18) &lt;&lt; "PRICE" &lt;&lt; setw(20) &lt;&lt; "QUANTITY" &lt;&lt; endl;
  
          for(int i=0; i &lt; cart.getCurrentSize(); i++) {
              cout &lt;&lt; items[i];
          }
  
          cout &lt;&lt; endl &lt;&lt; "The total price of the order is " &lt;&lt; cart.getTotalPrice() &lt;&lt; endl;
          // "---------------------------------------------------------------------"
          for(int i=0; i &lt; 40; i++)
              cout &lt;&lt; "-";
          cout &lt;&lt; endl;
  
          return 0;
  }
  </code></pre>