c++ array stl_C ++ STL中带有示例的array :: begin()和array :: end()函数

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值