- 数组::cbegin() 是C++中的一个内置函数,它返回 常量迭代器 指向数组中的第一个元素。它不能用于修改数组中的元素,使用array::begin()可以修改该元素。
语法:
array_name.cbegin()
参数: 该函数不接受任何参数。
返回值: 函数返回一个 常量迭代器 指向数组中的第一个元素。
项目1:
// CPP program to illustrate
// the array::cbegin() function
#include <bits/stdc++.h>
using
namespace
std;
int
main()
{
array<
int
, 5> arr = { 1, 5, 2, 4, 7 };
// Prints the first element
cout <<
"The first element is "
<< *(arr.cbegin()) <<
""
;
// Print all the elements
cout <<
"The array elements are: "
;
for
(
auto
it = arr.cbegin(); it != arr.cend(); it++)
cout << *it <<
" "
;
return
0;
}
输出:The first element is 1 The array elements are: 1 5 2 4 7
- 数组::cend() 是C++中的一个内置函数,它返回 常量迭代器 指向数组中最后一个元素之后的理论元素。
语法:
array_name.cend()
参数: 该函数不接受任何参数。
返回值: 函数返回一个 常量迭代器 指向数组中最后一个元素之后的理论元素。
项目1:
// CPP program to illustrate
// the array::cend() function
#include <bits/stdc++.h>
using
namespace
std;
int
main()
{
array<
int
, 5> arr = { 1, 5, 2, 4, 7 };
// prints all the elements
cout <<
"The array elements are: "
;
for
(
auto
it = arr.cbegin(); it != arr.cend(); it++)
cout << *it <<
" "
;
return
0;
}
输出:The array elements are: 1 5 2 4 7
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END