c – 搜索具有上限和下限的地图
发布时间:2020-12-16 07:53:05 所属栏目:百科 来源:网络整理
导读:STL新手问题: 关于函数std :: map :: upper_bound和std :: map :: lower_bound是否有效指定地图中实际不存在的键? 例 std::mapint,int intmap;std::mapint,int::iterator it1,it2;intmap[1]=10;intmap[2]=20;intmap[4]=40;intmap[5]=50;it1=intmap.lower_b
STL新手问题:
关于函数std :: map :: upper_bound和std :: map :: lower_bound是否有效指定地图中实际不存在的键? 例 std::map<int,int> intmap; std::map<int,int>::iterator it1,it2; intmap[1]=10; intmap[2]=20; intmap[4]=40; intmap[5]=50; it1=intmap.lower_bound (3); // Is this valid? it2=intmap.upper_bound (3); // Is this valid? 谢谢… 解决方法
是的,他们都是有效的.
intmap[1]=10; intmap[2]=20; intmap[4]=40; // <<---both lower_bound(3)/upper_bound(3) will points to here intmap[5]=50; lower_bound / upper_bound返回值将被插入的位置. 注意,如果要检查值键是否为地图,可以使用std::map::find (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |