title: Aligning output on the right in c++
body: <pre><code>#include&lt;iostream&gt;
  #include&lt;iomanip&gt;
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; right &lt;&lt; "Hello" &lt;&lt; setw(10) &lt;&lt; "World\n";
      cout &lt;&lt; right &lt;&lt; "Goodbye"  &lt;&lt; setw(10) &lt;&lt; "World\n";
  }
  </code></pre>
  
  <p>Why does this result in output like:</p>
  
  <pre><code>Hello    World
  Goodbye    World
  </code></pre>
  
  <p>Rather than:</p>
  
  <pre><code>Hello    World
  Goodbye  World
  </code></pre>
  
  <p>What am I doing wrong here?</p>
  
  <p>EDIT:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;iomanip&gt;
  using namespace std;
  
  int main()
  {
      cout    &lt;&lt; "Hello"  &lt;&lt;  " World";
      cout &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; "today\n";
      cout   &lt;&lt; "Goodbye"  &lt;&lt;  " World";
      cout &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; "today\n";
  }
  </code></pre>
  
  <p>If I try this, why is the "today" part misaligned?</p>