I'm new in C++ and I'm trying to catch an input value from console and assing it to a string variable. I don't know why at the first loop doesn't wait but at the second it does.
Here is the relevant code:
bool success = false;
string name;
string txtAge;
short age;
while (!success) {
cout<<"Person name: \n";
getline(cin,name);
cout<<"Person age: \n";
getline(cin, txtAge);
try {
age = lexical_cast<short>(txtAge);
Person newPerson(nombre, edad);
personList->Add(&newPerson);
success = true;
}
catch (...) {
cout << "Error message\n";
system("pause");
}
}
If anyone knows why is this happening and want to say it,I would be grateful for it. Have a nice day.