C++ How to loop through set in map? -
i stuck on 1 problem in school project: need set of numbers mapped key number. zz
class big integers ntl library, that's not important. program fails on inner loop message it_set2
can't iterable.
std::map<zz, std::set<zz>> mapa; std::map<zz, std::set<zz>>::iterator it_map; std::set<zz>::iterator it_set1, it_set2; (it_map = mapa.begin(); it_map != mapa.end(); ++it_map) { (it_set1 = it_map->second.begin(); it_set1 != it_map->second.end(); ++it_set1) { (it_set2 = ++it_set1; it_set2 != it_map->second.end(); ++it_set2) { /* function uses *it_set1, *it_set2 */ } } }
thanks help.
i suppose problem in inner loop. if want it_set2
point next element it_set1
pointing (but not incrementing it_set1
) should change third loop following: for(it_set2 = it_set1; ++it_set2 != it_map->second.end(); )
.
this make sure you're not going out of bounds , not incrementing it_set1
when not necessary.
Comments
Post a Comment