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

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.

主站蜘蛛池模板: 桃园市| 延津县| 西畴县| 安多县| 东海县| 乌拉特中旗| 图片| 修武县| 潼关县| 双城市| 监利县| 靖边县| 白城市| 平江县| 西畴县| 广水市| 吴忠市| 寿阳县| 武邑县| 清河县| 临漳县| 沙田区| 卓尼县| 福泉市| 云阳县| 故城县| 六盘水市| 汉川市| 万年县| 抚州市| 黑龙江省| 义马市| 周宁县| 宣汉县| 连州市| 西畴县| 镇平县| 台北县| 涪陵区| 故城县| 南阳市|