multiset max_size() in C++ STL with Examples

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to understand multiset max_size() in C++ STL.

The function max_size() returns the maximum number of elements a given container can hold.


 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main(){
   multiset<int> s;
   cout << "The multiset elements are: ";
   for (auto it = s.begin(); it != s.end(); it++)
      cout << *it << " ";
   cout << "\nThe max size of multiset: " << s.max_size();
   return 0;


The multiset elements are: 10 13 13 24 25
The max size of multiset: 461168601842738790
Published on 06-Apr-2020 17:24:33