title: I am trying to write out the results of a process to a text file, the issue I have is with the alignment of the columns
body: <p>I am sure someone somewhere has had this same issue but I have looked far and wide (including here on the stackoverflow) to find out how to properly align my columns in an output file. The following is the complete code I am using (for an event generator called Pythia 8 of which C++ is the primary language):</p>
  
  <pre><code>using namespace Pythia8;
  
  int main()
  {
      Pythia pythia;
      pythia.readString("Top:gg2ttbar = 1");
      pythia.init(2212, 2212, 14000.);
      ofstream myfile;
      myfile.open("ttbar.txt");
  
      for (int iEvent = 0; iEvent &lt; 1; ++iEvent)
      {
          if (!pythia.next()) continue;
  
          vector&lt;double&gt; part;
          for (int i = 0; i &lt; pythia.event.size(); ++i)
          {
              if (pythia.event[i].status() == 91) part.push_back(i);
          }
  
          myfile &lt;&lt; "N = " &lt;&lt; part.size() &lt;&lt; endl;
          for (int j = 0; j &lt; (int(part.size()) - 1); ++j)
          {
              myfile &lt;&lt; left &lt;&lt; setw(4) &lt;&lt; int(part[j]);
              myfile &lt;&lt; setw(4) &lt;&lt; left &lt;&lt; pythia.event[part[j]].name() &lt;&lt; "     "
                     &lt;&lt; right &lt;&lt; pythia.event[part[j]].id() &lt;&lt; "     "
                     &lt;&lt; pythia.event[part[j]].px() &lt;&lt; "     " &lt;&lt; pythia.event[part[j]].py()
                     &lt;&lt; "     " &lt;&lt; pythia.event[part[j]].pz() &lt;&lt; "     "
                     &lt;&lt; pythia.event[part[j]].m() &lt;&lt; "     " &lt;&lt; pythia.event[part[j]].pT() &lt;&lt; endl;
          }
  
      }
  
      pythia.stat();
      myfile.close();
      return 0;
  }    
  </code></pre>
  
  <p>The issue occurs near the bottom where the loop that writes out the text file starts, as it is currently written in the above code, the first two columns are mashed together:</p>
  
  <pre><code>N = 665
  1777pi-      -211     1.19978     0.715507     32.7878     0.13957     1.39694
  1779pi+      211     -8.24173     6.07047     -31.6818     0.13957     10.2361
  </code></pre>
  
  <p>That is the first couple lines of the output (the program shows the line number where a certain particle is produced and relevant information about it like the name, mass...etc.). I cannot seem to format it so I don't have to use the inserted spaces that I put in by hand. </p>