- Mastering C++ Programming
- Jeganathan Swaminathan
- 158字
- 2021-07-02 18:28:52
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.
推薦閱讀
- Advanced Machine Learning with Python
- iOS面試一戰到底
- Visual C++串口通信開發入門與編程實踐
- 程序員面試算法寶典
- Python爬蟲開發與項目實戰
- Building an RPG with Unity 2018
- ASP.NET Core 2 Fundamentals
- 學習OpenCV 4:基于Python的算法實戰
- Webpack實戰:入門、進階與調優
- Multithreading in C# 5.0 Cookbook
- Spring Security Essentials
- Spring技術內幕:深入解析Spring架構與設計原理(第2版)
- JSP程序設計實例教程(第2版)
- Qlik Sense? Cookbook
- 代碼閱讀