Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > handle cin errors

Reply
Thread Tools

handle cin errors

 
 
Nafai
Guest
Posts: n/a
 
      03-23-2005
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!
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      03-23-2005
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
 
Reply With Quote
 
 
 
 
E. Robert Tisdale
Guest
Posts: n/a
 
      03-23-2005
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?
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-23-2005
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
 
Reply With Quote
 
E. Robert Tisdale
Guest
Posts: n/a
 
      03-23-2005
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.
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-24-2005
"E. Robert Tisdale" <> wrote...
> [...]
> This is bad advice. It contradicts


When was it you admitted that anybody else's advice was good?
Stop trolling.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using cin.get() and cin.eof() ends up in an endless loop Fernando C++ 4 11-16-2011 07:19 PM
cin and cin.getline() Aleander C++ 5 03-06-2005 03:57 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
std::cin.ignore() and std::cin.clear() Chris Mantoulidis C++ 5 01-06-2004 11:08 PM
cin and cin.clear() problem TaiwanNoWhere C++ 8 10-17-2003 05:53 PM



Advertisments