이 튜토리얼에서는 C++ STL에서 multiset upper_bound()를 이해하는 프로그램에 대해 논의할 것입니다.
upper_bound() 함수는 매개변수로 제공된 것보다 큰 요소에 대한 포인터를 반환하고, 그렇지 않으면 컨테이너의 마지막 요소에 대한 포인터를 반환합니다.
예시
#include <bits/stdc++.h>
using namespace std;
int main(){
multiset<int> s;
s.insert(1);
s.insert(3);
s.insert(3);
s.insert(5);
s.insert(4);
cout << "The multiset elements are: ";
for (auto it = s.begin(); it != s.end(); it++)
cout << *it << " ";
auto it = s.upper_bound(3);
cout << "\nThe upper bound of key 3 is ";
cout << (*it) << endl;
it = s.upper_bound(2);
cout << "The upper bound of key 2 is ";
cout << (*it) << endl;
it = s.upper_bound(10);
cout << "The upper bound of key 10 is ";
cout << (*it) << endl;
return 0;
} 출력
The multiset elements are: 1 3 3 4 5 The upper bound of key 3 is 4 The upper bound of key 2 is 3 The upper bound of key 10 is 5