My goal is to read a string input after reading an int input. The problem is I'm either getting an error or getline() isn't waiting for input from console.
I tried the following
Original method:
int num;
string name;
cout << "Enter number: ";
cin >> num;
cout << "Enter name: ";
cin >> name;
However if I enter name which has multiple words, the prompt won't take any more inputs.
Second method:
I tried this
int num;
string name;
cout << "Enter number: ";
cin >> num;
cout << "Enter name: ";
getline(cin, name);
But according to this, this method is wrong.
Method 3:
Finally I tried this
int num;
string name;
cout << "Enter number: ";
//cin >> num;
getline(cin, num);
cout << "Enter name: ";
getline(cin, name);
But it gives me error error: no matching function for call to 'getline'