#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct coffeeBean
{
string name;
string country;
int strength;
};
std::vector<coffeeBean> coffee_vec[4];
int main(int argc, char ** argv)
{
coffee_vec[1].name;
return 0;
}
When I try to run this code I get 'class std::vector<coffeeBean>' has no member named 'name'
I thought we can access the struct this way. Am I doing something wrong?
You are creating an array of four vectors, not a vector with four elements.
In your code, coffee_vec[1]
refers to a vector<coffeeBean>
object, not a coffeeBean
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With