You probably have a line-feed character still in the buffer from a previous read. Accessing the input using >> will not remove the line-feed character from when you pressed the 'return' key for the previous input.
@curioustoknow,
Your code is most likely is somethin like this:
1 2 3 4 5 6 7 8 9 10 11
int main(){
//...
string str;
cin >> str;//a >> is causing the problem
//solution 1 would be to add cin.ignore here
//(which is better as it does not change program's behavior)
//soution 2 would be to replace this with getline(cin, str);
//...
getline(cin, em.locate.street);
//...
}
@Galik
What parameters do you use? Do you create a string for storing the rubbish? Seems kind of wasteful..
What parameters do you use? Do you create a string for storing the rubbish? Seems kind of wasteful..
It depends on the situation really. I wouldn't use getline() in every situation. But its not uncommon to have a general input string lying around while reading data.
cout<<"please enter the employee name : ";
// Here is the problem. This line does not extract the end of line
// marker that gets added to the input when the user presses the
// return key.
cin>>em.name;
// So when you do a getline() it will get that end of line character
// and stop there, because it has got everything up to end of line.
// FIX: To fix this, change the above statement
// to use getline(cin, em.name) and not cin >> em.name