这个 多重映射:下界(k) 在C++ STL中是一个内置函数,它返回一个迭代器指向容器中的键,它相当于参数中传递的K。如果多重映射容器中不存在k,则函数返回一个迭代器,指向刚好大于k的下一个元素。如果参数中传递的键超过容器中的最大键,则迭代器返回指向键+1和元素=0。
null
语法:
multimap_name.lower_bound(key)
参数: 此函数接受一个强制参数键,该键指定要返回其下界的元素。
返回值: 该函数返回一个迭代器,该迭代器指向容器中的键,该键相当于在参数中传递的k。如果多重映射容器中不存在k,则函数返回一个迭代器,指向刚好大于k的下一个元素。如果参数中传递的键超过容器中的最大键,则迭代器返回指向键+1和元素=0。
// C++ function for illustration // multimap::lower_bound() function #include <bits/stdc++.h> using namespace std; int main() { // initialize container multimap< int , int > mp; // insert elements in random order mp.insert({ 2, 30 }); mp.insert({ 1, 40 }); mp.insert({ 2, 60 }); mp.insert({ 2, 20 }); mp.insert({ 1, 50 }); mp.insert({ 4, 50 }); // when 2 is present auto it = mp.lower_bound(2); cout << "The lower bound of key 2 is " ; cout << (*it).first << " " << (*it).second << endl; // when 3 is not present it = mp.lower_bound(3); cout << "The lower bound of key 3 is " ; cout << (*it).first << " " << (*it).second << endl; // when 5 exceeds it = mp.lower_bound(5); cout << "The lower bound of key 5 is " ; cout << (*it).first << " " << (*it).second << endl; return 0; } |
输出:
The lower bound of key 2 is 2 30 The lower bound of key 3 is 4 50 The lower bound of key 5 is 6 0
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END