stl中map函數
C ++ STL映射:: max_size() (C++ STL map::max_size() )
It returns the maximum number of elements the container(map) is able to hold but at runtime, the size of the container may be limited to a value smaller than specified by max_size() by the amount of RAM available. It gives us an only a theoretical limit on the size of the container.
它返回容器(映射)能夠容納的最大元素數量,但是在運行時,容器的大小可能會限制為小于可用max_size()指定的可用RAM數量的值。 它僅對容器的大小提供了理論上的限制。
Syntax:
句法:
myMap.max_size()
Where, myMap is the object of class map.
其中, myMap是類映射的對象。
Parameters: None - It does not accept any parameters.
參數:無-不接受任何參數。
Return value: It simply returns the maximum number of elements container can hold.
返回值:它僅返回容器可以容納的最大元素數。
Example:
例:
#include <bits/stdc++.h>
using namespace std;
int main()
{
// create map container
map<int, int> myMap;
//insert an element in map
myMap.insert( pair<int, int>(200 , 100) );
cout<<"max size of Non-empty map : \n";
cout << "The max size of myMap is " << myMap.max_size();
map<char,char> EmpMap;
map<int, int> EmpMap2;
cout<<"max size of Empty-map : \n";
cout << "\nThe max size of EmpMap is " << EmpMap.max_size();
cout << "\nThe max size of EmpMap2 is " << EmpMap2.max_size();
return 0;
}
Output
輸出量
max size of Non-empty map :
The max size of myMap is 461168601842738790max size of Empty-map :
The max size of EmpMap is 461168601842738790
The max size of EmpMap2 is 461168601842738790
翻譯自: https://www.includehelp.com/stl/map-max-size-function-with-example-in-cpp-stl.aspx
stl中map函數