Problem with getline()
Feb 21, 2013 at 10:10pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
do {
cout << "First name: " ;
getline(cin, name);
system("CLS" );
cout << "Last name: " ;
getline(cin, lastname);
system("CLS" );
cout << "Adress: " ;
getline(cin, adress);
system("CLS" );
cout << "Phone Number: " ;
cin >> phone_number;
system("CLS" );
cout << "Input another persons information? < Y || N >: " ;
cin >> attempt;
i++;
}while (attempt == 'y' || attempt == 'Y' );
Problem is, first time it asks the user for input just fine. But if I press 'Y' to input another persons information. It completely ignores the 'first name' input and jumps straight to last name. How can this be?
Feb 21, 2013 at 10:42pm UTC
Because if enter 'y' you also press 'Enter', so getline(cin, name);
gets empty line.
Feb 21, 2013 at 11:14pm UTC
would (s)he have to use cin.clear then?
Topic archived. No new replies allowed.