STL vector中的end方法(8)
来源:互联网 发布:java获取浏览器地址 编辑:程序博客网 时间:2024/06/04 17:54
std::vector::end
- C++98
- C++11
iterator end() noexcept;const_iterator end() const noexcept;
返回一个超尾迭代器指向vector容器最后元素的再下一个元素(这个位置是没有元素存在的)。
这个超尾元素是一个假设紧跟容器最后一个元素的下一个位置的元素,但是该超尾迭代器本身是不指向任何元素的,因此不应该被解除引用。
因为标准库里面用于指示范围的函数并没有包含被超尾迭代器所指向的元素,这个函数通常联合begin一起来使用用于指出容器范围内的所有元素。区间范围为[begin,end)
如果容器是空的,那么这个函数的返回值和begin是一样的。
Parameters
noneReturn Value
An iterator to the element past the end of the sequence.返回值是一个超尾迭代器,指向超出序列范围外的一个位置。
If the vector object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.
如果vector对象本身具有const属性,那么将返回一个const_iterator,否则,返回一个普通的iterator.
Member types iterator and const_iterator are random access iterator types (pointing to an element and to a const element, respectively).
该迭代器的类型属于随机访问迭代器类型。
Example
12345678910111213141516
// vector::begin/end#include <iostream>#include <vector>int main (){ std::vector<int> myvector; for (int i=1; i<=5; i++) myvector.push_back(i); std::cout << "myvector contains:"; for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
Output:
myvector contains: 1 2 3 4 5
Complexity
Constant.Iterator validity
No changes.Data races
The container is accessed (neither the const nor the non-const versions modify the container).
容器将被访问。
No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. 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.
该方法不会抛出异常
利用复制构造器或者是赋值运算符得到的该iterator也不会抛出异常。
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
2014-8-11
于GDUT
- STL vector中的end方法(8)
- STL vector::end()
- STL vector中的insert方法
- STL array中的end方法(11)
- STL vector中的begin方法(3)
- STL vector中的front方法(4)
- STL vector中的rbegin方法(5)
- STL vector中的cbegin()方法(6)
- STL vector中的crbegin方法(7)
- STL vector中的cend方法(9)
- STL vector中的rend方法(10)
- STL vector中的crend()方法(11)
- STL vector中的reserve()方法(15)
- STL vector中的push_back方法(17)
- STL vector中的clear方法(18)
- STL vector中的at方法(20)
- STL vector中的data方法(21)
- STL vector中的pop_back方法(22)
- 服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS?
- IOS 基础知识 Foundation-NSString和NSMutableString的使用
- poj1145 括号间的读取与匹配
- 视图的使用
- 网络协议分析--Ethereal网络协议分析及介绍
- STL vector中的end方法(8)
- block 和 全局变量
- 索引-数学
- NSString
- linux中 you have newmail in /var/spool/mail/root是什么意思
- UVA - 10916 Factstone Benchmark
- 素数的筛选
- IOS技术文章摘选
- 输出操作符<< 的重载