You need cin.ignore() between two inputs:because you need to flush the newline character out of the buffer in between.
#include <iostream>
using namespace std;
int main() {
string word, line;
cout << "enter a word" << endl;
cin >> word;
cout << "enter a line" << endl;
cin.ignore();
getline(cin,line);
cout << "your word is " << word << endl;
cout << "your line is " << line << endl;
return 0;
}
For your second answer, when you enter whole string in first cin
, it takes only one word, and the rest is taken by getline
and thus your program will execute without taking input from getline
Demo