title: Error handling after doing strtol
body: <p>I am trying to read several numbers on <code>stdin</code>, one number on each line. I want to ignore any trailing text after number and strings if any on any line. To implement this I used the below code:</p>
  
  <pre class="lang-c++ prettyprint-override"><code>while (getline(cin, str)) {
      num = strtol(str.c_str(), NULL, 0);
  
      if (errno != ERANGE &amp;&amp; errno != EINVAL) {
          arr[i++] = num;
          req_pages_size++;
          cout &lt;&lt; arr[i-1] &lt;&lt; "\t";
      }
  
      str.clear();
  }
  </code></pre>
  
  <p>ISSUE: After unsuccessful conversion, errno doesn't get updated with an error value for successful conversion case. It's value remains the same for previous calls which was unsuccessful.</p>
  
  <p>Please let me know how to handle this issue?</p>