title: How does istream::ignore( ) work?
body: <p>I've been reading about istream::ignore( ) <a href="http://www.cplusplus.com/reference/istream/istream/ignore/" rel="nofollow">here</a>. I think I get the main idea of the function it does, but I've seen some examples of <a href="http://en.cppreference.com/w/cpp/io/basic_istream/ignore" rel="nofollow">accepting only numeric input</a> that uses this function, and I'm not sure why it works.</p>
  
  <p>Why would this code ignore everything except numeric input?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;limits&gt;
  
  int main()
  {
      std::istringstream input("1\n"
                               "some non-numeric input\n"
                               "2\n");
      for(;;) {
          int n;
          input &gt;&gt; n;
  
          if (input.eof() || input.bad()) {
              break;
          } else if (input.fail()) {
              input.clear(); // unset failbit
              input.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n'); // skip bad input
          } else {
              std::cout &lt;&lt; n &lt;&lt; '\n';
          }
      }
  }
  </code></pre>
  
  <p>I had thought that istream::ignore( ) would ignore any and all characters specified by a certain number until the delimiter..</p>