Issue with reading string into an array

Hello!

I'm having some difficulty inputting names of strings into an array. I've tried both getline() as well as cin, the output is the same. It skips over every other element in the array, only reading elements 0, 2, and 4.

Any help is appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
  void names(string students[])
{
    for (int i=0; i<MAX_STU; i++)
    {
        cout<<"Please input the first name of each student, after each student pressing enter: "<<endl;
        cin>>students[i];

        i++;
    }

    return;
}
for (int i=0; i<MAX_STU; i++)
{
cout<<"Please input the first name of each student, after each student pressing enter: "<<endl;
cin>>students[i];

i++;
}

you i++ in the loop body and loop statement. Only need one, by convention, unless you have a good reason, you do this in the loop statement not the body.
Last edited on
Wow, I feel so blind. Thank you!
Topic archived. No new replies allowed.