这个 多集::cbegin() 是C++ STL中的一个内置函数,它返回指向容器中第一个元素的常数迭代器。迭代器不能用于修改集合容器中的元素。迭代器可以相应地增加或减少以遍历集合。
null
语法:
constant_iterator multiset_name.cbegin()
参数: 该函数不接受任何参数。
返回值: 该函数返回指向容器中第一个元素的常量迭代器。
下面的程序演示了multiset::cbegin()方法。
C++
// C++ program to demonstrate the // multiset::cbegin() function #include <bits/stdc++.h> using namespace std; int main() { int arr[] = { 14, 10, 15, 11, 10 }; // initializes the set from an array multiset< int > s(arr, arr + 5); // Prints the first element cout << "The first elements is: " << *(s.cbegin()) << endl; // prints all elements in set for ( auto it = s.cbegin(); it != s.cend(); it++) cout << *it << " " ; return 0; } |
输出:
The first elements is: 1010 10 11 14 15
这个 多集::cend() 是C++ STL中的一个内置函数,它返回一个常数迭代器,指向容器中最后一个元素的位置。迭代器不能用于修改集合容器中的元素。迭代器可以相应地增加或减少,以便在集合中遍历。
语法:
constant_iterator multiset_name.cend()
参数: 该函数不接受任何参数。
返回值: 该函数返回一个常量迭代器,指向容器中最后一个元素之后的位置。
下面的程序演示了multiset::cend()方法。
C++
// C++ program to demonstrate the // multiset::cend() function #include <bits/stdc++.h> using namespace std; int main() { int arr[] = { 14, 10, 15, 11, 10, 15, 17, 17 }; // initializes the set from an array multiset< int > s(arr, arr + 8); // prints all elements in set for ( auto it = s.cbegin(); it != s.cend(); it++) cout << *it << " " ; return 0; } |
输出:
10 10 11 14 15 15 17 17
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END