Can operator>> read an int hex AND decimal?
<p>Can I persuade operator>> in C++ to read both a hex value AND and a decimal value?  The following program demonstrates how reading hex goes wrong.  I'd like the same istringstream to be able to read both hex and decimal.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;sstream&gt;

int main(int argc, char** argv)
{
    int result = 0;
    // std::istringstream is("5"); // this works
    std::istringstream is("0x5"); // this fails

    while ( is.good() ) {
        if ( is.peek() != EOF )
            is &gt;&gt; result;
        else
            break;
    }

    if ( is.fail() )
        std::cout &lt;&lt; "failed to read string" &lt;&lt; std::endl;
    else
        std::cout &lt;&lt; "successfully read string" &lt;&lt; std::endl;

    std::cout &lt;&lt; "result: " &lt;&lt; result &lt;&lt; std::endl;
}
</code></pre>
