官术网_书友最值得收藏!

Multiset

A multiset container works in a manner similar to a set container, except for the fact that a set allows only unique values to be stored whereas a multiset lets you store duplicate values. As you know, in the case of set and multiset containers, the values themselves are used as keys to organize the data. A multiset container is just like a set; it doesn't allow modifying the values stored in the multiset.

Let's write a simple program using a multiset:

#include <iostream>
#include <set>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
multiset<int> s = { 10, 30, 10, 50, 70, 90 };

cout << "\nMultiset values are ..." << endl;

copy ( s.begin(), s.end(), ostream_iterator<int> ( cout, "\t" ) );
cout << endl;

return 0;
}

The output can be viewed with the following command:

./a.out

The output of the program is as follows:

Multiset values are ...
10 30 10 50 70 90

Interestingly, in the preceding output, you can see that the multiset holds duplicate values.

主站蜘蛛池模板: 泗洪县| 城市| 扶沟县| 洛阳市| 贵溪市| 达拉特旗| 紫云| 华安县| 赤壁市| 南宁市| 麟游县| 大竹县| 和平县| 平塘县| 河西区| 桂东县| 涞源县| 天祝| 永年县| 徐汇区| 铁岭市| 河间市| 乐陵市| 额济纳旗| 阿图什市| 疏附县| 宝应县| 万全县| 临江市| 娱乐| 吉首市| 双峰县| 磴口县| 阿拉善右旗| 德庆县| 大化| 揭东县| 龙山县| 阿拉善盟| 庄浪县| 通州区|