title: C++ stringstream value extraction
body: <p>I am trying to extract values from <code>myString1</code> using <code>std::stringstream</code> like shown below:</p>
  
  <pre><code>// Example program
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  int main()
  {
    string myString1 = "+50years";
    string myString2 = "+50years-4months+3weeks+5minutes";
  
    stringstream ss (myString1);
  
    char mathOperator;
    int value;
    string timeUnit;
  
    ss &gt;&gt; mathOperator &gt;&gt; value &gt;&gt; timeUnit;
  
    cout &lt;&lt; "mathOperator: " &lt;&lt; mathOperator &lt;&lt; endl;
    cout &lt;&lt; "value: " &lt;&lt; value &lt;&lt; endl;
    cout &lt;&lt; "timeUnit: " &lt;&lt; timeUnit &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>mathOperator: +
  value: 50
  timeUnit: years
  </code></pre>
  
  <p>In the output you can see me successfully extract the values I need, the math operator, the value and the time unit.</p>
  
  <p>Is there a way to do the same with <code>myString2</code>? Perhaps in a loop? I can extract the math operator, the value, but the time unit simply extracts everything else, and I cannot think of a way to get around that. Much appreciated.</p>