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

更新於:2020-04-06

189 次瀏覽

開啟您的 職業生涯

完成課程以獲取認證

開始
廣告