title: c++ isalnum endless loop
body: <p>Greetings!</p>
  
  <p>Lets cut the excessive intro this time and get straight to the point.</p>
  
  <p>I have a problem in C++ using the isalnum method.</p>
  
  <p>the code:</p>
  
  <pre><code>int playAgainst = 0;
  do
  {
      cout &lt;&lt; "Who do you want to play against?(1/2)\n";
      cout &lt;&lt; "1: Human player\n";
      cout &lt;&lt; "2: Computer player\n";
      cin &gt;&gt; playAgainst
  } while(!isalnum(playAgainst) &amp;&amp; playAgainst != 0);
  </code></pre>
  
  <p>As seen in the code, I'm providing the user with a choice. Play against human or play against a computer.</p>
  
  <p>What I want is, as long as the user enters anything else then an integer value(cin >> playAgainst) to repeat the question. However, If i enter a char, or string value, it keeps looping endlessly. I am not 100% sure, but it would be obvious, if the problem is, that the non int value is already saved as the value for playAgainst.. How can I check in this bit of code if the input value is int before saving it? </p>
  
  <p>Or is the only possibility to save as a char/string and then check? </p>
  
  <p>If the latter is the case, a new problem arises. isalnum only accepts int as parameter, atleast from what I know. How will I check if that string or char is an int?</p>
  
  <p>Thank you for taking the time to read. And hopefully Ill be accepting a reply as answer soon ^^</p>
  
  <p>Thanks everyone for the answers.
  I have gotten what I wanted, and everything has been solved.</p>
  
  <p>The reason I chose for the accepted answer, is well... because initially, it made my code work the way I want it to. I want to accept multiple answers though..</p>