Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2002-08-22 16:07:20


On Thu, 22 Aug 2002 22:50:19 +0200, Gennaro Prota
<gennaro_prota_at_[hidden]> wrote:

>---------------------
>#include <sstream>
>#include <iomanip>
>#include <iostream>
>
>
>// The value of str must be the
>// string representation of 1+LONG_MAX.
>// Change it for your machine if needed.
>//
>int main(int argc, char* argv)
>{
> using namespace std;
>
> long num;
> stringstream str;
> str << "2147483648"; // 1+LONG_MAX
> str >> num;
>
> cout << "fail()? " << boolalpha << (str.fail()) << '\n';
>
>
> return 0;
>}
>----------------------------
>
>If you use 2+LONG_MAX instead then the stream is put in a failed
>state.

Ah! I forgot to say that if you experiment, for instance, with short
int and numeric_limits<short>::max() +1, +2, etc... the results are
even more surprising. This is related to core issue 23 and certainly
will need a fix when a resolution will be available from the C++
committee.

Genny.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk