c++ array stl
C ++ STL array :: back()函数 (C++ STL array::back() function)
back() function is a library function of array and it is used to get the last element of an array, it returns the reference to the last element in an array.
back()函数是array的库函数,用于获取数组的最后一个元素,它返回对数组中最后一个元素的引用。
Syntax:
句法:
array_name.back();
Parameters: None
参数:无
Return value: It returns a reference to the last element of array_name.
返回值:返回对array_name的最后一个元素的引用 。
Example:
例:
Input or array declaration:
array<int,5> values {10, 20, 30, 40, 50};
Function call:
values.back();
Output:
50
C ++ STL程序使用array:back()获取数组的最后一个元素 (C++ STL program to get the last element of an array using array:back())
#include <array>
#include <iostream>
using namespace std;
int main()
{
array<int,5> values {10, 20, 30, 40, 50};
//printing first element
cout<<"Last element is: "<<values.back()<<endl;
return 0;
}
Output
输出量
Last element is: 50
翻译自: https://www.includehelp.com/stl/array-back-function-with-example-in-cpp-stl.aspx
c++ array stl