C++Vector简单操作
来源:互联网 发布:淘宝上的优衣库代购 编辑:程序博客网 时间:2024/05/22 09:03
好像vector和QVector不太一样。
//iterator erase (const_iterator position);
//iterator erase (const_iterator first, const_iterator last);
//vector删除元素:
// An iterator pointing to the new location of the element that followed the last element erased by the function call.
// This is the container end if the operation erased the last element in the sequence.
// Member type iterator is a random access iterator type that points to elements.
#include <QtCore/QCoreApplication>#include <qDebug>#include <vector>using namespace std;bool compare(const int &v1,const int &v2){return v1 < v2;}void print(vector<int> &vInt){qDebug()<<"size: "<<vInt.size();for(vector<int>::iterator it=vInt.begin(); it!=vInt.end(); ++it)qDebug()<<*it;}int main(int argc, char *argv[]){QCoreApplication a(argc, argv);vector<int> vInt;vInt.push_back(5);vInt.push_back(1);vInt.push_back(6);vInt.push_back(2);vInt.push_back(13);vInt.push_back(4);vInt.push_back(7);vInt.push_back(3);print(vInt);///删除某一元素for(vector<int>::iterator it=vInt.begin(); it!=vInt.end(); ){if(*it==13){it=vInt.erase(it);break;}else++it;}print(vInt);//排序操作sort(vInt.begin(),vInt.end(),compare);vInt.erase(vInt.begin(),vInt.begin()+3);print(vInt);return a.exec();}/*size: 8516213473size: 75162473size: 44567.....*/erase返回一个指向最后一个被erase的元素的下一个元素指针。
- C++Vector简单操作
- Vector相关简单操作
- C++STL中vector容器类的简单操作
- c++vector简单实现
- 【STL C++】简单实现vector
- C++——vector操作
- C++vector的使用总结及常用vector操作
- c/c++ vector 的简单实现
- Vector 的简单实现 C++11
- (C++)Vector 简单的底层实现
- c#MQ简单操作
- 【C#-Hashtable简单操作】
- c简单位操作
- C/C++——vector的基本操作总结
- vector操作
- vector 操作
- vector操作
- vector操作
- window 开始运行指令(方便使用而已)
- 1-15 实验12 ZigBee无线传感器网络远程数据采集系统
- 监听树的选择事件
- 二叉树树的先序遍历,中序遍历和后序遍历
- JAVA 对象引用,以及对象赋值
- C++Vector简单操作
- Oracle数据库在Server 2008中的使用
- android:gravity和android:layout_gravity区别
- OpenJDK源码研究笔记(五)-缓存Integer等类型的频繁使用的数据和对象,大幅度提升性能(一道经典的Java笔试题)
- UVA - 10056 What is the Probability ?
- UVa 11417 GCD (欧拉φ函数)
- java多线程总结二:后台线程(守护线程)
- Jtree 的监听
- NYIST_12周赛(一)题目题解