getline

can we use getline function throught loop to input multiple names..?
my code in not working properly.. it take input in name for only once at first time.. please help me... the code is..

# include <iostream>
# include <conio.h>
# include <string.h>
using namespace std;
struct emp
{
int emp_Id;
string emp_name;
int salary;
};

int main()
{
emp e[10];
cout<<"Enter data of 10 Employee\n\n";
for(int i=0; i<10; i++)
{
cout<<"Enter the name of Employee no."<<i+1<<" : \n";
getline(cin,e[i].emp_name);
cout<<"Enter the ID of Employee no."<<i+1<<" : \n";
cin>>e[i].emp_Id;
cout<<"Enter the Salary of Employee no."<<i+1<<" : \n";
cin>>e[i].salary;
}
for(int i=0; i<10; i++)
{
cout<<"The name of employee"<<i+1<<"is : \t"<<e[i].emp_name<<"\n";
cout<<"The ID of employee"<<i+1<<"is : \t"<<e[i].emp_Id<<"\n";
cout<<"The Salary of employee"<<i+1<<"is : \t"<<e[i].salary<<"\n";
}

getch();
return 0;
}
Your problem is the mix of >> and getline(). See

http://www.cplusplus.com/articles/S3wTURfi/
Topic archived. No new replies allowed.