#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;
}
当我尝试运行此代码,我得到'class std::vector<coffeeBean>' has no member named 'name'
我以为我们可以访问该结构这样成员。难道我做错了什么?类的std ::向量没有命名
在声明向量你需要像使用数组一样使用'()'或'{}',而不是'[]'。 – NathanOliver