numeric overflow from cin

A

anonimo

Hello,

how can I filter numeric overflow exceptions from cin as in cin >> d,
where d is double?

Unfortunately, std::ios::failure that cin might throw when enabling
cin.exceptions does not garantuee that the error is related to overflows
necessarily
 
A

Alf P. Steinbach /Usenet

* anonimo, on 18.10.2010 02:18:
Hello,

how can I filter numeric overflow exceptions from cin as in cin >> d, where d is
double?

Unfortunately, std::ios::failure that cin might throw when enabling
cin.exceptions does not garantuee that the error is related to overflows
necessarily

The exception support in iostreams is just impractical.

There may be some way to do what you want without exceptions enabled (and if so
then probably James Kanze will chime in with a solution), but as a practical
matter, read in a line using std::getline from the <string> header, then parse
the spec using C library strtod, checking results as per the documentation.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top