multiset count() function in C++ STL Last Updated : 06 Oct, 2021 Comments Improve Suggest changes 5 Likes Like Report The multiset::count() function is a built-in function in C++ STL that searches for a specific element in the multiset container and returns the number of occurrences of that element. Syntax: multiset_name.count(val) Parameters: The function accepts a single parameter val which specifies the element to be searched in the multiset container. Return Value: The function returns the count of elements which is equal to val in the multiset container. Below programs illustrates the multiset::count() function: Program 1: C++ // C++ program to demonstrate the // multiset::count() function #include <bits/stdc++.h> using namespace std; int main() { int arr[] = { 15, 10, 15, 11, 10, 18, 18, 20, 20 }; // initializes the set from an array multiset<int> s(arr, arr + 9); cout << "15 occurs " << s.count(15) << " times in container"; return 0; } Output: 15 occurs 2 times in container Program 2: C++ // C++ program to demonstrate the // multiset::count() function #include <bits/stdc++.h> using namespace std; int main() { int arr[] = { 15, 10, 15, 11, 10, 18, 18, 18, 18 }; // initializes the set from an array multiset<int> s(arr, arr + 9); cout << "18 occurs " << s.count(18) << " times in container"; return 0; } Output: 18 occurs 4 times in container The time complexity of the multiset::count() function is O(K + log(N)), where K is the total count of integers of the value passed. Create Quiz Comment G gopaldave Follow 5 Improve G gopaldave Follow 5 Improve Article Tags : Misc C++ STL CPP-Functions cpp-multiset +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like