title: Splitting strings by newline character in C++
body: <p>If I have two tables stored in <code>std::string</code> variables, how could I display them side-by-side?  In particular...</p>
  
  <p>I have <code>std::string table1</code> which contains the following:</p>
  
  <pre><code> X | Y
  -------
   2 | 3
   1 | 3
   5 | 2
  </code></pre>
  
  <p>I have <code>std::string table2</code> which contains the following:</p>
  
  <pre><code> X | Y
  -------
   1 | 6
   1 | 1
   2 | 1
   3 | 5
   2 | 3
  </code></pre>
  
  <p>I need to modify them (or really just print them to standard output) so that the following appears:</p>
  
  <pre><code> X | Y    X | Y
  -------  -------
   2 | 3    1 | 6
   1 | 3    1 | 1
   5 | 2    2 | 1
            3 | 5
            2 | 3
  </code></pre>
  
  <p>In other words, I have two tables stored in <code>std::string</code> variables with newline characters separating the rows. </p>
  
  <p><strong>I would like to print them to screen (using <code>std::cout</code>) so that the tables appear side-by-side, vertically aligned at the top.  How could I do this?</strong></p>
  
  <p>For example, <em>if</em> I could do something like <code>std::cout &lt;&lt; table1.nextToken('\n')</code> where <code>nextToken('\n')</code> gives the next token and tokens are separated by the <code>'\n'</code> character, then I could devise a method to cycle through all tokens, and once all of <code>table1</code> tokens are used, I could then simply print space characters so that the remaining tokens of <code>table2</code> are properly horizontally aligned.  But, such a <code>nextToken(std::string)</code> function does not exist --- I don't know of it, at least.</p>