在本教程中,我们将讨论一个程序,以了解C ++ STL中的map equal_range。
此函数返回一对迭代器,这些迭代器限制了与给定参数等效的键所在的容器的范围。
#include <bits/stdc++.h>
using namespace std;
int main() {
//初始化容器
map<int, int> mp;
mp.insert({ 4, 30 });
mp.insert({ 1, 40 });
mp.insert({ 6, 60 });
pair<map<int, int>::iterator,
map<int, int>::iterator>
it;
it = mp.equal_range(1);
cout << "The lower bound is " << it.first->first<< ":" << it.first->second;
cout << "\nThe upper bound is "<< it.second->first<< ":" << it.second->second;
return 0;
}输出结果
The lower bound is 1:40 The upper bound is 4:30