request for member '', which is of non-class type

I am trying to build a struct array and input the different attributes to that struct array with a loop but I am being prompted with an error message saying "request for member ‘volume’ in ‘s’, which is of non-class type ‘water_bottle [3]’"

struct water_bottle{
string color;
string volume;
};

int main(){

water_bottle s[3];

for(int i = 0; i < 3; i++){
cin >> s.color << endl;
cin >> s.volume << endl;
}
s is an array of water_bottle objects, not an individual water_bottle.
Also, cin and cout are two different streams; you can't feed an endl into cin using <<.

1
2
3
4
for(int i = 0; i < 3; i++){
    cin >> s[i].color;
    cin >> s[i].volume;
}
Last edited on
Topic archived. No new replies allowed.