c++ array stl
C ++ STL array :: begin()和array :: end()函数 (C++ STL array::begin() and array::end() functions)
array::begin() function is a library function of array and it is used to get the first element of the array, it returns an iterator pointing to the first element of the array.
array :: begin()函数是array的库函数,用于获取数组的第一个元素,它返回指向数组的第一个元素的迭代器。
array::end() function is a library function of array and it is used to get the last element of the array, it returns an iterator pointing to the last element of the array.
array :: end()函数是array的库函数,用于获取数组的最后一个元素,它返回一个指向数组最后一个元素的迭代器。
Syntax:
句法:
array::begin();
array::end();
Parameters: None
参数:无
Return value: Function return iterators pointing to the first and last elements of an array.
返回值:函数返回迭代器指向数组的第一个和最后一个元素。
Example:
例:
Input or array declaration:
array<int,5> arr {10, 20, 30, 40, 50};
Function call:
auto it=arr.begin();
cout<<*it;
it=arr.end();
cout<<*it;
Output:
10 50
C ++ STL程序演示array :: begin()和array :: end()函数的示例 (C++ STL program to demonstrate example of array::begin() and array::end() functions)
#include <array>
#include <iostream>
using namespace std;
int main()
{
array<int,5> numbers {10, 20, 30, 40, 50};
array<string,5> cities {"New Delhi", "Mumbai", "Gwalior"};
cout<<"Elements of numbers array..."<<endl;
for(auto it=numbers.begin(); it!=numbers.end(); it++)
cout<<*it<<" ";
cout<<endl;
cout<<"Elements of cities array..."<<endl;
for(auto it=cities.begin(); it!=cities.end(); it++)
cout<<*it<<" ";
cout<<endl;
return 0;
}
Output
输出量
Elements of numbers array...
10 20 30 40 50
Elements of cities array...
New Delhi Mumbai Gwalior
翻译自: https://www.includehelp.com/stl/array-begin-and-array-end-functions-with-example-in-cpp-stl.aspx
c++ array stl