By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

handle cin errors

P: n/a
Hello. I need to handle cin errors like these:

....
int n;
cout << "Type a number: ";
cin >> n;
// Check user actually typed a number.
....
CONSOLE:

Type a number: asdf >ENTER
....
Programs does strange things
....
How can I do that?

Thanks!
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Nafai wrote:
Hello. I need to handle cin errors like these:

...
int n;
cout << "Type a number: ";
cin >> n;
// Check user actually typed a number.
...
CONSOLE:

Type a number: asdf >ENTER
...
Programs does strange things
...
How can I do that?


Read the FAQ (http://www.parashift.com/c++-faq-lite/), your question
and an answer has been put there.

V
Jul 23 '05 #2

P: n/a
Victor Bazarov wrote:
Nafai wrote:
Hello. I need to handle cin errors like these:

...
int n;
cout << "Type a number: ";
cin >> n;
// Check user actually typed a number.
...

CONSOLE:

Type a number: asdf >ENTER
...
Programs does strange things
...

How can I do that?


Read the FAQ (http://www.parashift.com/c++-faq-lite/),
your question and an answer has been put there.


[15.3] How can I get std::cin to skip invalid input characters?
Jul 23 '05 #3

P: n/a
E. Robert Tisdale wrote:
Victor Bazarov wrote:
Nafai wrote:
Hello. I need to handle cin errors like these:

...
int n;
cout << "Type a number: ";
cin >> n;
// Check user actually typed a number.
...

CONSOLE:

Type a number: asdf >ENTER
...
Programs does strange things
...

How can I do that?

Read the FAQ (http://www.parashift.com/c++-faq-lite/), your question
and an answer has been put there.

[15.3] How can I get std::cin to skip invalid input characters?


[5.5] What do I do if someone else posts a question that's already
in the FAQ?

And see note #1.

V
Jul 23 '05 #4

P: n/a
Victor Bazarov wrote:
E. Robert Tisdale wrote:
Victor Bazarov wrote:
Read the FAQ (http://www.parashift.com/c++-faq-lite/),
your question and an answer has been put there.

I couldn't tell which FAQ you were talking about
and I don't think that Nafai could either.
[15.3] How can I get std::cin to skip invalid input characters?


[5.5] What do I do if someone else posts a question
that's already in the FAQ?

And see note #1.


Note #1: Please don't give them the location
of the appropriate FAQ. E.g., don't say,
"Look at FAQ [10.3]" or "Look in section [10]".
It's the old give-them-a-fish vs. teach-them-to-fish problem.

This is bad advice. It contradicts

Note #2: Please be polite. I'm hoping we can avoid
"RTFM" or "RTFFAQ" euphemisms (or worse!).

Please *don't* send new subscribers on a "wild goose chase".
Cite and quote the relevant FAQ
just as if you were citing and/or quoting a relevant passage
from the ANSI/ISO C++ standards documents.
Jul 23 '05 #5

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote...
[...]
This is bad advice. It contradicts


When was it you admitted that anybody else's advice was good?
Stop trolling.
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.