title: How can I validate an integer input
body: <p>For example I have the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      int test = 0;
      cout &lt;&lt; "Please input a number:";
  
      while(!(cin &gt;&gt; test))
      {
          cout &lt;&lt; "Invalid input";
      }
  
      if(test  == 1)
      {
          cout &lt;&lt; "Test is 1";
      }
      else
      {
          // Do something
      }
     return 0;
  }
  </code></pre>
  
  <p>If I input <code>1abc</code> to the test variable it still continues to process the <code>if</code> statement even though the input is wrong. How could I ignore all the input made and just accept pure numbers in it?</p>