title: istream extraction operator: how to detect parse failure?
body: <p>How can I detect whether the istream extraction failed like this?</p>
  
  <pre><code>string s("x");
  stringstream ss(s);
  int i;
  ss &gt;&gt; std::ios::hex &gt;&gt; i;
  </code></pre>
  
  <p>EDIT -- Though the question title covers this, I forgot to mention in the body: I really want to detect whether the failure is due to bad formatting, i.e. parsing, or due to any other IO-related issue, in order to provide proper feedback (an malformed_exception("x") or whatever).</p>