using getline(cin, string) on a loop not working properly

Monday, May 5, 2014

I am using a for loop to input data in a structure array, I am not ableto get a string variable to have white spaces, such that the stored name is two+ words as opposed to one, can anyone help me properly use getline in a loop?


It works when I do not use a loop, not sure what is causing the error in this program though.


Below is the sample that is giving me trouble:


void Data_Input(int numberOfStudents, int numberOfTests, classroom* &student){



for (int count = 0; count < numberOfStudents; count++){
cout << "For student number " << count + 1 << ", please input the following data:";
cout << "Student Name: ";
//cin >> student[count].Name;
**getline(cin, student[count].Name);**

}
}


}







http://ift.tt/1htjJyk