473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

handle cin errors

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
5 2020
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: steve | last post by:
Hi, In my script (phpnuke), whenever there is access to database, there is this line of code: message_die(GENERAL_ERROR, ’some error msg’, ’’, __LINE__, __FILE__, $sql); Is there a more...
2
by: E B via SQLMonster.com | last post by:
how to handle sql errors with severity less then 10 in .NET i call to stored procedure which raise error with severity 10 for example however in c# i can't cach this error (with severiry >= 11 it...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
17
by: ahaupt | last post by:
Hi all, I'm currently writing a load of class libraries, but not the main application iteslf. I want to provide some method for reporting errors back to the main application. At the moment...
3
by: figelwump | last post by:
Hello, I'd like to be able to write an application that runs on a Windows XP machine and can capture and handle javascript errors from any web site that a user might encounter while using IE on...
3
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
3
by: Peterwkc | last post by:
Hello all C++ expert programmer, I have a handle class which point to another class and use the pointer as object. I follow the code from C++ articles submited by someone in this forum....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.