//构造函数
//multiset()
multiset
//指定一个比较函数来创建multiset对象
struct KeyCompare
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
multiset
//multiset(const _Myt& _Right)
multiset
//multiset(_Iter _First, _Iter _Last)
int arr[] = { 1, 1, 3, 42, 21, 31, 21 };
multiset
const char* szArray[] = { "hfdd", "do", "mmd" };
multiset
//插入元素
ms1.insert(2); //2
//在可能的位置之前插入元素
ms1.insert(ms1.begin(), 7); //2 7
//插入区间元素
int arr2[] = { 3, 9, 6 };
ms1.insert(arr2, arr2 + 3); //2 3 6 7 9
//遍历元素
multiset
for (iter = ms1.begin(); iter != ms1.end(); ++iter)
{
cout << *iter << " ";
}
cout << endl;
//反向遍历元素
multiset
for (rIter = ms1.rbegin(); rIter != ms1.rend(); ++rIter)
{
cout << *rIter << " ";
}
cout << endl;
multiset
if (rFind == ms1.end())
{
cout << "not find" << endl;
}
else
{
cout << "find" << endl;
}
//删除元素
ms1.erase(ms1.begin()); //3 6 7 9
//删除键值33的元素
ms1.erase(33); //3 6 7 9
//删除区间元素
ms1.erase(ms1.begin(), ++ms1.begin()); //6 7 9
//删除所有元素
ms1.clear();
//容器是否为空
bool b = ms1.empty();
//实际元素个数
size_t count = ms1.size();
//键值等于7的元素的个数
size_t num = ms1.count(7);
//键值大于等于3的第一个元素的位置
multiset
if (uIter == ms4.end())
{
cout << "not found" << endl;
}
else
{
int i = 0;
iter = ms4.begin();
while (iter != uIter)
{
++i;
++iter;
}
cout << "find index:" << i << endl; //2
}
//键值大于3的第一个元素的位置
ms4.upper_bound(3);