In the following simple program,
int main()
{
string name;
char sex;
cout << "enter M or F: ";
cin.get(sex);
cout << "enter name: ";
[B]getline(cin, name);[/B]
cout << name << " is " << sex << endl;
return 0;
}
after the user typed in a character "M" or space, then the program is finished and it seems the value of "name" is taken to be the ENTER that was pressed after typing in "M". So far, the only thing I could do is either
(a) not to enter any character, but only press ENTER when prompted to enter "sex"--which is of course not desired result; or,
(b) change the "getline(cin, name)" to "cin >> name", which also is not desired (can't take spaces within the string).
Is there a way to fix this? Many thanks for your time!