This is my main program,
int main () {
string command;
cin>>command;
if(command == "keyword")
{
string str, str2, str3, str4;
cout << "Enter first name: ";
getline (cin,str);
cout << "Enter last name: ";
getline (cin,str2);
cout << "Enter age: ";
getline (cin,str3);
cout<<"Enter country: ";
getline (cin,str4);
cout << "Thank you, " << str <<" "<<str2 <<" "<<str3<<" "<<str4<< ".\n";
}
}
When keyword is entered, the program immediately outputs :
Enter first name: Enter last name:
completely bypassing the ability to enter the first name.
after this just eat the end of the line
Otherwise the ‘\n’ in the line where you input command is not consumed and the next readline reads just it. HTH