Re: Avoiding Input Failure in C++
On Dec 23, 11:33 pm, orgthingy
<orgthi...@usersDOTsourceforge.net> wrote:
So basically: my book didn't explain it well :-/ ! (It's good
book and all, but not on this point :-P)
so how can I avoid input failure? ..to those who are confused
by my question, i mean how to avoid getting double-input into
an int variable? and so on
First, I'm not too sure what you are really asking for. If the
input is coming from a human, you can't avoid input failure; all
humans make mistakes, mistype things, etc., from time to time.
So you can't avoid the failure, you have to detect it and
respond correctly to it.
Detecting the failure is trivial: if you try to input a
particular type with istream, and the input does not have an
acceptable format, the stream will be set to an error state,
which you can (and always should) test. Resynchronizing can be
more complicated.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34