Reputation: 13
The following code doesn't give the second prompt to "enter message". How do I fix it?
cout << "Enter shifts:" << endl;
cin >> shifts;
cout << "Enter message:" << endl;
getline(cin, msg);
Upvotes: 0
Views: 652
Reputation: 243
when you enter shifts there is a newline which read by geline funtion. So You need to ignore that newline.
write :
cout << "Enter shifts:" << endl;
cin >> shifts;
getchar();
cout << "Enter message:" << endl;
getline(cin, msg);
Upvotes: 1
Reputation:
try this one
cout << "Enter shifts:" << endl;
cin >> shifts;
cout << "Enter message:" << endl;
cin.ignore();
getline(cin, msg);
use cin.ignore();
before using getline
anywhere.
Upvotes: 2