Problems with cin.get

Dear all,
can anyone please tell me what is the problem with this code?

class person {
private:
char name[15];
int age;
public:
void getData() {
cout<<"Enter name";
cin.get(name,15);
cout<<"Enter age";
cin>>age;
}
void showData() {
cout<<name<<age;
}
};

int main() {
person* ptrPerson[3];
for (int i=0;i<3;i++) {
ptrPerson[i] = new person();
ptrPerson[i]->getData();
}

for (int i=0;i<3;i++) {
ptrPerson[i]->showData();
}
return 0;
}


And then when i run the program, it asks for the first person name but on every subsequent call, it omits asking name and directly asks for the person age.

Sample run
Enter name
Enter age

Enter name Enter age
Enter name Enter age... and so on

I have tried it with string data type and also by using dynamic memory allocation but all in vain, can anyone please help?
Topic archived. No new replies allowed.