title: C++ getline results in segmentation fault when the end of the string is reached
body: <p>I have this simple code splitting a string made of equalities separated by ampersands:</p>
  
  <pre><code>std::string cmd = "par1=1&amp;par2=ciao&amp;par3=1.2e4"
  
  std::stringstream ss(cmd);
  std::string argdef;
  std::vector&lt;std::string&gt; pairs(0);
  
  while (std::getline(ss, argdef, '&amp;'))
    pairs.push_back(argdef);
  </code></pre>
  
  <p>I correctly collect three equalities into the vector 'pairs', but the while loop continues beyond the end of the stream, and I get a segmentation fault. How to avoid this?</p>