title: Output formatting in C++
body: <p>Hi i am printing some output data to a txt file , which will be used by another program , but to make the data pleasant to eyes need to align them in columns.
  Could someone help me please-</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;     // std::cout, std::fixed, std::scientific
  
  int main () {
  
  
            int r=1;
            double value1=-1.187;
            double value2=5.273430;
            double value3=5.27343056896;
            double value4=0.0000056868;
            int i=1;
            int r1=10;
             int r2=2;
            double value5=1.1875985;
            double value6=-5.273430;
            double value7=-0.27343056896;
            double value8=1.0000056868;
  
  
          std::cout.precision(6);
          std::cout &lt;&lt; std::fixed;
         // std::cout &lt;&lt; std::setw( 8 );
          //std::cout &lt;&lt; std::setfill ('0');
          std::string space="   ";
  
          std::cout&lt;&lt;r&lt;&lt;space&lt;&lt;value1&lt;&lt;space&lt;&lt;value2&lt;&lt;space&lt;&lt;value3&lt;&lt;space&lt;&lt;value4&lt;&lt;space&lt;&lt;i&lt;&lt;std::endl;
          std::cout&lt;&lt;r2&lt;&lt;space&lt;&lt;value5&lt;&lt;space&lt;&lt;value1&lt;&lt;space&lt;&lt;value4&lt;&lt;space&lt;&lt;value3&lt;&lt;space&lt;&lt;i&lt;&lt;std::endl;
          std::cout&lt;&lt;r1&lt;&lt;space&lt;&lt;value5&lt;&lt;space&lt;&lt;value6&lt;&lt;space&lt;&lt;value7&lt;&lt;space&lt;&lt;value8&lt;&lt;space&lt;&lt;i&lt;&lt;std::endl;
  
  
    return 0;
  }
  
  
  The result looks like this
  
  1   -1.187000   5.273430   5.273431   0.000006   1
  
  2   1.187599   -1.187000   0.000006   5.273431   1
  
  10   1.187599   -5.273430   -0.273431   1.000006   1
  
  
  but i really want is
  
  1   -1.187000   5.273430   5.273431   0.000006   1
  
  2    1.187599  -1.187000   0.000006   5.273431   1
  
  10   1.187599  -5.273430  -0.273431   1.000006   1
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/PQTXk.png" rel="nofollow">enter image description here</a></p>