vector 遍历及下标访问
来源:互联网 发布:淘宝卖家号被冻结 编辑:程序博客网 时间:2024/05/16 17:51
vector 常规的遍历方法有以下方法:
1.for 遍历
vector<int> theVector;...vector<int>::iterator theIterator;for (theIterator = theVector.begin(); theIterator != theVector.end(); theIterator++) { cout << *theIterator; }
2. for each 遍历
for each (ServerStatusListener* listener in m_serverStatusListenerList) {listener->OnCPSStatusChanged(cpsStatus);}
3.for 遍历,用下标
for (vector<int>::size_type ix = 0; ix != 10; ++ix)
鉴于第3种模式,可以采用下标的方式取得vector 中的值
//vector 中有3条数据if (ipporttmp.size() == 3){vector<string>::size_type sindex=0;iptmp= ipporttmp[sindex]; //第一条数据port1 =atoi(ipporttmp[sindex +1].c_str()); //第二条数据port2 =atoi(ipporttmp[sindex +2].c_str()); //第三条数据}
4. for 遍历,使用size()
bool process(vector<int>& a){int sum = 0;for (int i = 0;i < a.size(); ++i){sum += a[i];}return sum > 100? true:false;}
- vector 遍历及下标访问
- 实测 vector遍历,迭代器方式快于下标访问方式
- Vector数组可以使用下标直接访问
- Vector用数组下标访问的条件
- VECTOR 常用用法、存储、遍历访问
- map的下边访问和vector的下标访问的区别
- c++之Vector容器数据两种取值方法(指针访问,数组下标访问)
- C++ vector的访问(resize,pu_back与下标访问的区别)
- <s iterator>遍历list 及取list下标
- vector对象、下标操作
- vector的下标操作
- vector下标操作
- 通过下标遍历std::vector,一个非常隐蔽的越界错误
- vector写邻接表及遍历
- NYOJ 贪心 vector的使用,是一个数组,有重复数据,可以下标访问
- 对vector继承并重载[]操作符,可以用负数下标访问数组
- map这种容器的下边访问和Vector等容器的下标访问有本质的区别。
- c++中vector的遍历及元素删除
- 链接参考
- C#老生常谈之异步调用的参数及返回值
- 面试题 c++
- spring 组件注解
- JSON for java入门总结
- vector 遍历及下标访问
- 斐波那契数
- windows安装Apache,注册服务出现“(OS 5)拒绝访问。 : AH00369: Failed to open the WinNT service manager..."错误
- VC 多线程同步方式操作串口
- why the blog borned? 此 博客为何而生?
- spring依赖注入
- 荷兰王子昏迷18个月去世
- OpenSSL - DES
- Windows下批量重命名