I'm collage student and I'm trying to do simple struct program I wrote this code then the second getline returns empty string.
#include <iostream>
#include <string>
using namespace std;
struct person
{
string name;
string phone;
int age;
float salary;
};
int main()
{
person p1;
cout << "Enter your name : ";
getline(cin, p1.name);
cout << "Enter your age : ";
cin >> p1.age;
cout << "Enter your phone number : ";
getline(cin, p1.phone);
cout << "Enter your salary : ";
cin >> p1.salary;
cout << "------------------------------------------------------------\n";
cout << "Your personal information : \n";
cout << "Name : " << p1.name << endl;
cout << "Age : " << p1.age << endl;
cout << "Phone number : " << p1.phone << endl;
cout << "Salary : " << p1.salary << endl;
return 0;
}
I though it was from the IDE but when I tried it on deferent IDE on deferent device I got the same result