unordered_multimap size() function in C++ STL
The unordered_multimap::size() is a built-in function in C++ STL which returns the size of the unordered_multimap. It denotes the number of elements in that container.
Syntax:
unordered_multimap_name.size()
Parameters: The function does not accept any parameters.
Return Value: It returns an integral values which denotes the size of the containers.
Below programs illustrates the above function:
Program 1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_multimap< int , int > sample1, sample2;
sample1.insert({ 10, 100 });
sample1.insert({ 50, 500 });
sample2.insert({ 20, 200 });
sample2.insert({ 30, 300 });
sample2.insert({ 30, 150 });
cout << "The size of Sample1 is: " << sample1.size();
cout << "\nKey and Elements of Sample1 are:" ;
for ( auto it = sample1.begin(); it != sample1.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} " ;
}
cout << "\n\nThe size of Sample2 is: " << sample2.size();
cout << "\nKey and Elements of Sample2 are:" ;
for ( auto it = sample2.begin(); it != sample2.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} " ;
}
return 0;
}
|
Output:
The size of Sample1 is: 2
Key and Elements of Sample1 are:{50, 500} {10, 100}
The size of Sample2 is: 3
Key and Elements of Sample2 are:{20, 200} {30, 150} {30, 300}
Program 2:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_multimap< char , char > sample1, sample2;
sample1.insert({ 'a' , 'A' });
sample1.insert({ 'g' , 'G' });
sample2.insert({ 'b' , 'B' });
sample2.insert({ 'c' , 'C' });
sample2.insert({ 'd' , 'D' });
cout << "The size of Sample1 is: " << sample1.size();
cout << "\nKey and Elements of Sample1 are:" ;
for ( auto it = sample1.begin(); it != sample1.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} " ;
}
cout << "\n\nThe size of Sample2 is: " << sample2.size();
cout << "\nKey and Elements of Sample2 are:" ;
for ( auto it = sample2.begin(); it != sample2.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} " ;
}
return 0;
}
|
Output:
The size of Sample1 is: 2
Key and Elements of Sample1 are:{g, G} {a, A}
The size of Sample2 is: 3
Key and Elements of Sample2 are:{d, D} {b, B} {c, C}
Last Updated :
21 Aug, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...