ANKI_YUME
ANKI_YUME

Reputation: 13

Using cin function

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

Answers (2)

Robin Halder
Robin Halder

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

user5028722
user5028722

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

Related Questions