title: C++ cin only accept numeric values
body: <p>I've written this piece of code that allows the user to choose input either the value 1 or 2. This is working perfectly fine aside from one minor issue:</p>
  
  <p>If the user inputs something like "1asdaosd" the input is recognized only as 1.</p>
  
  <p>I've tried using the isdigit function but I still didn't manage to make this work.</p>
  
  <p><pre><code><code>bool validInput;
      do
      {
          cout &lt;&lt; "Choose the game type: ";
          cin &gt;&gt; gametype;
          validInput = true;
          if (cin.fail())
          {
              validInput = false;
              cin.clear();
              cin.ignore(std::numeric_limits&lt;int&gt;::max(), '\n');
          }
          if (gametype&lt;1 || gametype&gt;2) {
              validInput = false;
          }
      } while (!validInput);</code>
  </pre></code></p>
  
  <p>The expected behaviour should be:</p>
  
  <p>Anything other than "1" or "2" shouldn't be considered a validInput and therefore repeating the cycle. What happens is that "1asdasd" or "2aods" is considered a validInput but I want it to fail.</p>