title: c++ reading mixed ints and strings from cin
body: <p>I'm trying to read input that has ints and strings, in this case an expression like 1 2 +. I've been trying to use cin.fail() to determine if the input is numeric.</p>
  
  <pre><code>int x;
  string s;
  if (cin &gt;&gt; x){
    // do something
  } else {
    cin &gt;&gt; s;
    //do something else
  }
  </code></pre>
  
  <p>I realized this skips input but can't figure out how to solve the problem.
  Would I have to read everything as a string then check and convert to int? I would like to find a better solution if possible and would be very grateful for any assistance.</p>