Can anyone explain to me why my getline() statement from my code is not looping as I could expect, I want the code inside the while loop to execute forever but then my code only loops the code but skips the getline() function. I'll provide the screenshot...my code is:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int age;
while(true)
{
cout << "Enter your name: ";
getline(cin, name);
cout << "Enter your age: ";
cin >> age;
cout << "Age: " << age << "\tName: " << name << "\n\n";
}
}
the output loops only the cin function and no solution I have found so far that put things clear. My code runs like: