C++ C++;:与操作员不匹配<;尝试迭代boost::无序映射时<;字符串,int>;

C++ C++;:与操作员不匹配<;尝试迭代boost::无序映射时<;字符串,int>;,c++,boost,unordered-map,boost-iterators,boost-unordered,C++,Boost,Unordered Map,Boost Iterators,Boost Unordered,我有以下代码: boost::unordered_map<std::string, int> map; map["hello"]++; map["world"]++; for(boost::unordered_map<std::string, int>::iterator it = map.begin(); it < map.end(); it++){ cout << map[it->first]; } boost::无序地图; 地图[

我有以下代码:

boost::unordered_map<std::string, int> map;
map["hello"]++;
map["world"]++;

for(boost::unordered_map<std::string, int>::iterator it = map.begin(); it < map.end(); it++){
    cout << map[it->first];
}
boost::无序地图;
地图[“你好”]+;
地图[“世界”]+;
for(boost::无序映射::迭代器it=map.begin();it
当我试图编译时,我得到了以下错误,但不知道为什么

error: no match for ‘operator<’ in ‘it < map.boost::unordered::unordered_map<K, T, H, P, A>::end [with K = std::basic_string<char>, T = int, H = boost::hash<std::basic_string<char> >, P = std::equal_to<std::basic_string<char> >, A = std::allocator<std::pair<const std::basic_string<char>, int> >, boost::unordered::unordered_map<K, T, H, P, A>::iterator = boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const std::basic_string<char>, int> >*, std::pair<const std::basic_string<char>, int> >]()
错误:与“运算符”不匹配请尝试:


作为循环终止条件的
(而不是
it
)。

如果是迭代器,则必须使用
=操作员:

boost::unordered_map<std::string, int>::iterator it = map.begin();
for(; it != map.end(); ++it){
    cout << map[it->first];
}
boost::无序映射::迭代器it=map.begin();
for(;it!=map.end();++it){
cout-first];
}

你不能像编译器说的那样使用
@aly,因为没有
操作符。。。因为地图是无序的公平点,我将接受一次,因此让我(等待的时间最短)向量迭代器例如定义运算符<,以便我们可以使用此终止条件。我想这取决于迭代器是如何实现的。老实说,我不知道迭代器,但从另一方面来说,将迭代器用于vector是合乎逻辑的,但我从来没有见过这种用法。无论如何,循环始终使用!=operatorIt与连续无关,简单的问题是标准声明迭代器应该与!=和==只要迭代器属于同一个集合并且在范围内(包括超过末尾的迭代器),就可以很好地定义它们。因为标准没有说迭代器之间必须支持运算符<,所以boost在这种情况下没有实现它。当然,我说了内存来解释迭代器为什么使用!==比较一下。对boost来说不是特别的
boost::unordered_map<std::string, int>::iterator it = map.begin();
for(; it != map.end(); ++it){
    cout << map[it->first];
}