我是新來的使用迭代器。我已經使用了下面的代碼,我使用迭代器解析列表中的所有元素,以確定元素是否存在於列表中。迭代器使用 - 林特警告
list<int> pendingRsp;
list<int>::iterator it1;
for(int i = 1; i <= 5; i++)
pendingRsp.push_back(i *10);
for(it1 = pendingRsp.begin(); it1 != pendingRsp.end(); it1++)
{
if((*it1) == 50)
{
found = true;
break;
}
}
的代碼工作正常,但我得到了下面的皮棉警告:
信息1702: '!=操作符'!運算符既是一個普通的函數」操作符=(常量對< < 1> ,< 2 >> &,常量對< < 1>,< 2 >> &)」和成員函數名單::爲const_iterator ::運算!=(常數爲const_iterator &)常量'
什麼上述w^arning是什麼意思?運算符在列表和迭代器中重載!=運算符的實現之間有衝突嗎?
與問題無關,但使用'std :: find'而不是for循環。 – 2012-01-09 09:34:40
是的std :: find是一個更好的。感謝您的建議 – inquisitive 2012-01-09 09:43:25