我试图在 C++ 中的迭代器中访问结构元素,但编译器只是给我一个错误,即结构不包含该元素。我正在尝试执行以下操作:
typedef struct
{
string str;
int frequenzy;
} word;
bool isPresent = false;
for(std::vector<word>::iterator itr=words.begin(); itr!=words.end(); ++itr)
{
if(*itr.str.compare(currentWord)==0){
isPresent = true;
*itr.frequenzy++;
}
}
我收到以下消息:
lab7.cc: In function 'int main()':
lab7.cc:27:13: error: 'std::vector<word>::iterator' has no member named 'str'
lab7.cc:29:11: error: 'std::vector<word>::iterator' has no member named 'frequen
zy'
为什么这不可能?