Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

map equal_range() trong C++ STL


Trong hướng dẫn này, chúng ta sẽ thảo luận về chương trình để hiểu map equal_range trong C++ STL.

Hàm này trả về một cặp iterator giới hạn phạm vi chứa key tương đương với tham số cho trước.

Ví dụ

#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; }

Đầu ra

The lower bound is 1:40 The upper bound is 4:30