I was working on a problem given in my course book. The target was to create a
struct
to hold the serial number, the name and the phone number of 10
Members, all the data to be given by the user, and then present the data on the screen.
I made the program do everything asked in the question, but there is a problem.
The problematic part is this code segment:
1 2 3 4 5 6 7 8
|
for (int i = 0;i<10;i++)
{
Memdat[i].SerialNumber = i+1;
cout << endl << "Serial Number: " << Memdat[i].SerialNumber << endl;
cout << "Please enter the name of the Member: ";
getline (cin,Memdat[i].Name);
//More code...
}
|
As you can see, I am using
getline to get the user's name into a string in an object
Memdat[10], of type
Member.
Name is of type string.
When I run the program, it asks for the name the first time, but then ignores it.
That is:
Serial Number:
1
Please enter the name of the Member:
Nisheeth
Please enter the number of the Member:
............
Serial Number:
2
Please enter the name of the Member:
Please enter the number of the Member:
............
|
and so on.
Can someone tell me what am I doing wrong, and how can I correct it?
{I am using MS VC++ Express 2010 in Windows 7 64-Bit}