I’m attempting to read in user inputted values about put them into a string class array, but I’m getting a BAD EXCESS error, I’m guessing its something really simple that I’m doing wrong. Here is what I got. Any help would be great
int main()
{
const int SIZE = 5;
string fruity[SIZE];
int i;
cout << "Enter the names of five kinds of fruit:" << endl;
for(i = 0; i < SIZE; i++)
{
cout << "Enter Name of Fruit" << endl;
getline(cin, fruity[i]);
}
cout << fruity[i] << endl;
return 0;
}
This is invalid. Do this instead:
Because at that point your
iwill be equal toSIZE, andfruity[SIZE]is invalid.