#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