unordered_multimap::max_size()是C++ STL中的内置函数,该函数返回unordered_multimap容器可以容纳的最大元素数。
用法:
unordered_multimap_name.max_size()
参数:该函数不接受任何参数。
返回值:它返回一个整数值,该整数值表示容器可以容纳的元素的最大大小。
以下示例程序旨在说明上述函数:
示例1:
// C++ program to illustrate the
// unordered_multimap::max_size()
#include <bits/stdc++.h>
using namespace std;
int main()
{
// declaration
unordered_multimap<int, int> sample1;
// inserts key and element
// in sample1
sample1.insert({ 10, 100 });
sample1.insert({ 50, 500 });
cout << "The max number of elements that sample1 can hold: "
<< sample1.size();
cout << "\nKey and Elements of Sample1 are:";
for (auto it = sample1.begin(); it != sample1.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} ";
}
return 0;
}
输出:
The max number of elements that sample1 can hold: 2 Key and Elements of Sample1 are:{50, 500} {10, 100}
示例2:
// C++ program to illustrate the
// unordered_multimap::max_size()
#include <bits/stdc++.h>
using namespace std;
int main()
{
// declaration
unordered_multimap<char, char> sample1, sample2;
// inserts key and element
// in sample1
sample1.insert({ 'a', 'A' });
sample1.insert({ 'g', 'G' });
cout << "The max number of elements that sample1 can hold: "
<< sample1.size();
cout << "\nKey and Elements of Sample1 are:";
for (auto it = sample1.begin(); it != sample1.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} ";
}
return 0;
}
输出:
The max number of elements that sample1 can hold: 2 Key and Elements of Sample1 are:{g, G} {a, A}
相关用法
- C++ multimap maxsize()用法及代码示例
- C++ log()用法及代码示例
- C++ div()用法及代码示例
- C++ fma()用法及代码示例
- C++ strrchr()用法及代码示例
- C++ array get()用法及代码示例
- C++ array at()用法及代码示例
- C++ unordered_map end( )用法及代码示例
- C++ strcspn()用法及代码示例
- C++ iswpunct()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 unordered_multimap max_size() function in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。