C++ multiset size()C++ Multiset size() function is used to find the number of elements present in the multiset container. SyntaxMember type size_type is an unsigned integral type. ParameterNone Return valueThe size() function returns the number of elements present in the multiset. ComplexityConstant. Iterator validityNo changes. Data RacesThe container is accessed. Concurrently accessing the elements of a multiset container is safe. Exception SafetyThis function never throws exception. Example 1Let's see the simple example to calculate the size of the multiset: Output: num multiset contains 5 elements. In the above example, multiset num contains 5 elements. Therefore size() returns 5 elements. Example 2Let's see a simple example to calculate initial size of multiset and size of multiset after adding elements: Output: Initial size of multiset = 0 Size of multiset after inserting elements = 6 In the above example, first multiset is empty hence, size() function will return 0 and after inserting 6 elements it will return 6. Example 3Let's see a simple example: Output: 100 200 200 300 400 In the above example, It simply uses the size() function in while loop and prints the elements of multiset until the size of multiset. Example 4Let's see a simple example: Output: Enter three sets of marks: 340 235 340 Size of marks multiset is: 3 List of Marks: 235 340 340 In the above example, the program first creates marks multiset interactively. Then it displays the total size of marks multiset and all the elements 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