C++ multiset max_size()C++ Multiset max_size() function is used to get the maximum number of size a multiset container can hold. SyntaxMember type size_type is an unsigned integral type. ParameterNone Return valuemax_size() function returns the maximum allowed length of the multiset container. ComplexityConstant. Iterator validityNo changes. Data RacesThe container is accessed. Concurrently accessing the elements of a multiset container is safe. Exception SafetyThis member function never throws exception. Example 1Let's see the simple example to calculate the maximum size of the multiset: Output: Maximum size of a 'multiset' is 461168601842738790 In the above example, max_size() function returns the maximum size of the multiset. Example 2Let's see a simple example: Output: The multiset contains 1000 elements. In the above example, member max_size is used to check beforehand whether the multiset will allow for 1000 elements to be inserted. Example 3Let's see a simple example to find the max size of an empty multiset and a non-empty multiset: Output: The max size of mp1 is 461168601842738790 The max size of mp2 is 461168601842738790 In the above example, there are two multisets i.e. m1 and m2. m1 is a non-empty multiset and m2 is an empty multiset. But the maximum size of both multisets is the same. Example 4Let's see a simple example: Output: Enter the number of family members: 8 Enter the name of each member: Ram Archana Aman Nikita Divya Amita Kashish Ram Total number of population of city multiset: 461168601842738790 Total member of family is:8 Name of family members: Name ________________________ Aman Amita Archana Divya Kashish Nikita Ram Ram In the above example, the program first creates city multiset interactively with given number of size. Then it displays the total size a city multiset can contain, total size of a fmly and all the names and their age available in the multiset. Next TopicC++ multiset |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India