how to write something in a array of characters in an array of stuct

i have problem, how to write in an array of character in an array of struct?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 struct student{
     char name[20];
     char id [5];
     double marks;
}
int main ()
{
  struct student s[10];
  for ( int i=0;i<10;i++){
      cout<<"enter the student name: ";
      cin.getline(s[i].name,20);
      cout <<"enter the student id: ";
      cin.getline(s[i].id,5);
      cout<<"enter the student marks: ";
      cin>>s[i].marks;
}


when i launch the program, i can enter the name only for the first but i can not enter the name of the rest, how to fix this ?
That’s because it’s catching the '\n' that the normal cin never swallowed. After the normal cin >> put cin.ignore(1000,'\n'); and it should work
Topic archived. No new replies allowed.