map equal_range() 函式在 C++ STL 中
在本教程中,我們將討論一個程式來了解 C++ STL 中的 map equal_range 等效範圍。
此函式返回一對迭代器,它界定在其中包含與給定引數等效金鑰的容器範圍。
示例
#include <bits/stdc++.h> using namespace std; int main() { //initializing container 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
廣告