stl max函数
C ++ STL array :: max_size()函数 (C++ STL array::max_size() function)
max_size() function is a library function of array and it is used to get maximum size of an array. It returns the total number of elements that an array can hold.
max_size()函数是数组的库函数,用于获取数组的最大大小。 它返回一个数组可以容纳的元素总数。
Syntax:
句法:
array_name.max_size();
Parameters: None
参数:无
Return value: Total number of elements that an array can hold.
返回值:数组可以容纳的元素总数。
Example:
例:
Input or array declaration:
array<int,5> values {10, 20, 30, 40, 50};
Function call:
values.max_size();
Output:
5
C ++ STL程序使用array:max_size()获取数组可以容纳的最大元素数 (C++ STL program to get the maximum number of elements that an array can hold using array:max_size())
#include <array>
#include <iostream>
using namespace std;
int main()
{
array<int,5> arr1 {10, 20, 30, 40, 50};
array<int,10> arr2 {10, 20, 30};
array<int,0> arr3; //array of 0 size
//printing size of arrays
cout<<"size of arr1: "<<arr1.max_size()<<endl;
cout<<"size of arr2: "<<arr2.max_size()<<endl;
cout<<"size of arr3: "<<arr3.max_size()<<endl;
return 0;
}
Output
输出量
size of arr1: 5
size of arr2: 10
size of arr3: 0
Ref: std::array::max_size()
参考: std :: array :: max_size()
翻译自: https://www.includehelp.com/stl/array-max_size-function-with-example-in-cpp-stl.aspx
stl max函数