vector::begin
2016-07-23 12:39
239 查看
Return iterator to beginning
Returns an iterator pointing to the first element in the vector.
Notice that, unlike member vector::front, which returns a reference to the first element, this function returns arandom
access iterator pointing to it.
If the container is empty, the returned iterator value shall not be dereferenced.
none
An iterator to the beginning of the sequence container.
If the vector object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.
Member types iterator and const_iterator are random access iterator types
(pointing to an element and to a const element, respectively).
---------------------------------------------------
// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
for (int i=1; i<=5; i++) myvector.push_back(i);
cout << "myvector contains:";
vector<int>::iterator it;
for (it = myvector.begin() ; it != myvector.end(); ++it)
cout << ' ' << *it;
cout << endl;
return 0;
}
Output:
----------------------------------
Returns an iterator pointing to the first element in the vector.
Notice that, unlike member vector::front, which returns a reference to the first element, this function returns arandom
access iterator pointing to it.
If the container is empty, the returned iterator value shall not be dereferenced.
Parameters(参数)
none
Return Value
An iterator to the beginning of the sequence container.If the vector object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.
Member types iterator and const_iterator are random access iterator types
(pointing to an element and to a const element, respectively).
// vector::begin/end #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector; for (int i=1; i<=5; i++) myvector.push_back(i); cout << "myvector contains:"; for (vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it) cout << ' ' << *it; cout << endl; return 0; }
---------------------------------------------------
// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
for (int i=1; i<=5; i++) myvector.push_back(i);
cout << "myvector contains:";
vector<int>::iterator it;
for (it = myvector.begin() ; it != myvector.end(); ++it)
cout << ' ' << *it;
cout << endl;
return 0;
}
Output:
myvector contains: 1 2 3 4 5 |
相关文章推荐
- Openstack贡献者须知 2 — 社区工作运作 & 代码贡献流程
- 解决磁盘io紧张的一种临时方法
- 通道类型
- Git 一篇搞定基本操作
- 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
- Redis教程分享系列:1.Redis基础入门
- ggplot2--legend图例的修改
- session与cookie的区别---
- Java泛型的实现:原理与问题
- 复杂度nlog(n)之归并排序
- 整数在内存中的表达
- 通过nfs挂载共享目录的方式搭建lamp平台并安装wordpress(一)
- kobject.c 添加注释
- 面试题29:数组中出现次数超过一半的数字
- 最小树形图
- 用Jplayer做的一个带动画的播放器
- 校外分散实习(13)
- 《架构探险》之数据访问层代码优化
- 【VS开发】win7下让程序默认以管理员身份运行
- Java 打印n行杨辉三角数据