title: C++ getInt() function (have a java equivalent attached)
body: <p>I'm admittedly not the most experienced with C++, but am surprised to be having issues with getting such a simple function to work properly.  All I'm wanting is a function to get a user's input and ensure it obtains an integer(without crashing due to unexpected input) and then return that value to the calling function.  It should not accept any special characters or spaces whatsoever.  Essentially, I want it to be just like the Java equivalent that I'll post below:</p>
  
  <pre><code>public static int getInt()
  {
      boolean isNum = false; //test variable
      String str; //to hold input
  
      do
      {
          str = keyboard.nextLine();
          if (!(isNum = str.matches("\\d+")))
          {
              System.out.println("Enter a valid whole number, try again.");
          }
      } while(!isNum);
  
      return Integer.parseInt(str);
  }
  </code></pre>