473,396 Members | 1,853 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.

here i can't input address, after getting salary it takes input hire_date, what shou

void getdata()
{
cout<<"SALARY = ";
cin>>salary;
ignore(cin,100);
cout<<"ADDRESS = ";
getline(cin,address);
cout<<"HIRE DATE = ";
getline(cin,hire_date);
cout<<"PHONE = ";
getline(cin,phone);
cout<<"DATE OF BIRTH = ";
getline(cin,dob);
}
Dec 3 '16 #1
1 1005
weaknessforcats
9,208 Expert Mod 8TB
What's this for?

Expand|Select|Wrap|Line Numbers
  1. ignore(cin,100);

Parsing input is a really advanced programming skill because you have no idea what the user will enter or when the data entry is finished.

Add to this the problem of cin >> data where an error occurs, like trying to put an A into an int. This causes the input stream to go into a fail state. Every subsequent cin will check the fail state and if it is turned on the cin fails. The effect is that on the first error it looks like every cin in the rest of the program is disabled since they all fail. Worse, when this happens you can't stop it.

For beginners, I suggest you enter exactly what your progrsm requires and nothing else. And, I would do this after you have completely tested your code by using hardcoded values. This way you can stay focused on the data entry parse and not be tripped up by logic errors in the rest of the program.

Just to cin >> to an int you need code like:

Expand|Select|Wrap|Line Numbers
  1. bool GetInt(int* data)
  2. {
  3.     cin >> *data;
  4.     if (cin.good())
  5.     {
  6.       return true;
  7.     }
  8.     else
  9.     {
  10.         cin.clear();
  11.         return false;
  12.     }
  13. }
Even here you can see that you can't flush an input buffer because a)you don't know if the user has finished entering data, and b) your program is suspended while the user enters data. That means the input buffer is not yours so you can't flush it. All you can do is clear the error flag.

The only action you can take is if the error flag is set you can display a message and then terminate your program.

---unless you write your own version of cin which is what actual developers do.
Dec 3 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: santa19992000 | last post by:
can I use scanf to get input (some times user enters input sometimes not, just hit keyboard)?. It displays to enter IP address, if user wants to change, then he enters, otherwise he hits keyboard,...
2
by: Ravi J | last post by:
Hello, in an ASP.NET page, when the user selects certain button, I would like a small browser window to popup and ask user for some input. Once the user enters the data and submits through a...
4
by: Iceman.Aragorn | last post by:
I'm having an odd problem where im reading input from a comm port (the maker of the software that exports the data TO the comm port is unhelpful). What im reading is fixed length (13 character)...
3
by: dei3cmix | last post by:
Hey, I am having a problem with a program I am working on. Basically, the first part of the program gets input from a file using cin.getline. Then the second part, (still in the same main as the...
1
by: Chris Carlen | last post by:
Hi: I'm writing a Python program, a hex line editor, which takes in a line of input from the user such as: -e 01 02 "abc def" 03 04 Trouble is, I don't want to split the quoted part where...
1
by: Ben Brown | last post by:
I'm having some problems.. I have some javascript generated input elements with dynamic names and values. ex: <input name = "t1Name" .../> <input name = "t2Name" .../> ..... <input name =...
0
by: yawnmoth | last post by:
I'm trying to get a list of all the input elements of a form tag and am having some difficulty doing so. First, here's my XHTML: <div> <form action=""> <input type="text" name="a" /> </div>...
5
by: yawnmoth | last post by:
I'm trying to get a list of all the input elements of a form tag and am having some difficulty doing so. First, here's my XHTML: <div> <form action=""> <input type="text" name="a" /> </div>...
5
by: myra | last post by:
Hi, The problem is: I am trying to get the function call tree by using the profiling functions __cyg_profile_func_enter and __cyg_profile_func_exit. But it is printing the address of these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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.