【发布时间】:2014-11-19 09:54:09
【问题描述】:
我在学校项目中遇到了一个问题:我需要一组映射到键号的数字。 ZZ 是 NTL 库中的大整数类,但这并不重要。我的程序在内部循环中总是失败,并显示it_set2 无法迭代。
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
*/
}
}
}
感谢您的帮助。
【问题讨论】:
-
您的示例正在为我编译和运行。 (ideone.com/mi2bFV)
-
@tgmath:仅适用于空地图。我猜 OP 的地图不是空的 ;)
-
那么一个失败的例子可能会有所帮助。 :)
标签: c++ map set containers