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

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.

主站蜘蛛池模板: 辉南县| 集贤县| 蒙城县| 太仓市| 宕昌县| 寿光市| 伊金霍洛旗| 吴桥县| 安龙县| 仁怀市| 东阿县| 阳春市| 高尔夫| 济源市| 彩票| 景泰县| 定陶县| 昭通市| 芮城县| 吉安县| 应城市| 周至县| 涿鹿县| 静乐县| 镶黄旗| 伊吾县| 合肥市| 兴城市| 富源县| 乡城县| 溆浦县| 龙岩市| 常山县| 峨边| 志丹县| 达拉特旗| 景德镇市| 沾化县| 河南省| 佛学| 陵川县|