【发布时间】:2013-01-31 03:47:51
【问题描述】:
为什么在对向量的迭代器中访问对的值时会出现以下错误?
vector< pair<int,string> > mapper;
if(Hash(input, chordSize) != id){
mapper.push_back(make_pair(tmp, input));
}
for (vector< pair<int,string> >::iterator it = mapper.begin(); it != mapper.end(); ++it)
{
cout << "1st: " << *it.first << " " // <-- error!
<< "2nd: " << *it.second << endl; // <-- error!
}
错误信息:
main_v10.cpp:165:25: 错误:‘std::vector >::iterator’没有名为‘first’的成员 main_v10.cpp:165:56: 错误:‘std::vector > >::iterator’没有名为‘second’的成员
我该如何解决这个问题?
【问题讨论】:
-
您可能想阅读运算符优先级,结帐
*和.优先级:en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B