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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top