vector::cend (c++ 11)
2016-07-23 15:18
441 查看
public member function
<vector>
Return const_iterator to end
Returns a const_iterator pointing to the past-the-end element in the container.
A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by vector::end,
but it cannot be used to modify the contents it points to, even if the vector object is not itself const.
If the container is empty, this function returns the same as vector::cbegin.
The value returned shall not be dereferenced.
none
A const_iterator to the element past the end of the sequence.
Member type const_iterator is a random access iterator type that points to a const element.
// vector::cbegin/cend
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector = {10,20,30,40,50};
cout << "myvector contains:";
for (auto it = myvector.cbegin(); it != myvector.cend(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
Output:
Constant.
No changes. 该方法不会对其他迭代器的有效性造成影响。
The container is accessed. 该容器应该是可访问的。
No contained elements are accessed by the call, but the iterator returned can be used to access them. Concurrently accessing or modifying different elements is safe.
No-throw guarantee: this member function never throws exceptions.
The copy construction or assignment of the returned iterator is also guaranteed to never throw.
<vector>
std::vector::cend
const_iterator cend() const noexcept;
Return const_iterator to end
Returns a const_iterator pointing to the past-the-end element in the container.
A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by vector::end,
but it cannot be used to modify the contents it points to, even if the vector object is not itself const.
If the container is empty, this function returns the same as vector::cbegin.
The value returned shall not be dereferenced.
Parameters
none
Return Value
A const_iterator to the element past the end of the sequence.Member type const_iterator is a random access iterator type that points to a const element.
// vector::cbegin/cend
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector = {10,20,30,40,50};
cout << "myvector contains:";
for (auto it = myvector.cbegin(); it != myvector.cend(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
Output:
myvector contains: 10 20 30 40 50 |
Complexity (复杂性)
Constant.
Iterator validity
No changes. 该方法不会对其他迭代器的有效性造成影响。
Data races
The container is accessed. 该容器应该是可访问的。No contained elements are accessed by the call, but the iterator returned can be used to access them. Concurrently accessing or modifying different elements is safe.
Exception safety
No-throw guarantee: this member function never throws exceptions.The copy construction or assignment of the returned iterator is also guaranteed to never throw.
相关文章推荐
- vector::cbegin (c++11)
- 大话设计模式12----外观模式
- C++ vector用法
- 并查集C++实现
- leetcode_c++:栈: Implement Queue using Stacks(232)
- c++ 在windwos上创建盘符,并且,监控盘符里面任一文件的变动事件
- 谈谈8年C++面向对象设计的经验体会
- C/C++头文件大全
- leetcode_c++:栈: Implement Stack using Queues(225)
- 模拟实现strstr函数
- Google C++编程规范--《空格的使用》
- leetcode_c++:栈: Basic Calculator(224)
- C++小常识笔记
- C99 新增了复数类型(_Complex)和虚数类型(_Imaginary)。简单来说,C99 提供了三种复数类型:float _Complex,double _Complex,和 long do
- 一个整型数组里除了两个数之外,其他数都出现了两次。找出这两个出现一次的数。
- wince 遍历文件夹,删除文件夹,及文件夹内文件
- C99布尔类型
- 高质量C/C++编译指南 学习笔记
- #define中的一种用法
- 解决hash冲突的方法