내 학교 프로젝트에서 한 가지 문제에 봉착했습니다. 키 번호에 매핑 된 숫자가 필요합니다. ZZ
은 NTL 라이브러리의 큰 정수를위한 클래스이지만 중요하지는 않습니다. 내 프로그램은 항상 it_set2
을 반복 할 수 없다는 메시지와 함께 내부 루프에서 실패합니다.C++지도에서 세트를 반복하는 방법?
std::map<ZZ, std::set<ZZ>> mapa;
std::map<ZZ, std::set<ZZ>>::iterator it_map;
std::set<ZZ>::iterator it_set1, it_set2;
for (it_map = mapa.begin(); it_map != mapa.end(); ++it_map) {
for (it_set1 = it_map->second.begin(); it_set1 != it_map->second.end(); ++it_set1) {
for (it_set2 = ++it_set1; it_set2 != it_map->second.end(); ++it_set2) {
/*
some function that uses *it_set1, *it_set2
*/
}
}
}
도움 주셔서 감사합니다.
예제가 컴파일되고 실행 중입니다. (https://ideone.com/mi2bFV) – tgmath
@tgmath : 빈지도에만 해당됩니다. 나는 OP의지도가 비어 있지 않다고 생각한다.) – bitmask
그러면 실패한 예제가 도움이 될 것이다. :) – tgmath