僅在此簡單介紹QVector的一些常見函數,有興趣的可以查下QT,在QT中介紹的很詳細
構造函數,QVector的構造函數很多樣化,常見的有
1 QVector() 無參的構造函數 2
3 QVector(int size) 構造一個大小為size個 值為默認值的一個vector 4
5 QVector(int size,const T &value) 構造一個大小為size個 值為T &value的一個vector 6
7 QVector(const QVector<T> &other)構造一個值為QVector<T> &other的vector
1 // 將元素插入到vector的末尾
2
3 void append(const T &value) 4
5 void append(const QVector<T> &value) 6
7 void push_back(const T &value) 8
9 void push_back(const QVector<T> &value) 10
11 // 將元素插入到vector的開始
12
13 void prepend(const T &value) 14
15 void prepend(const QVector<T> &value) 16
17 void push_front(const T &value) 18
19 void push_front(const QVector<T> &value) 20
21 等同於vector.insert(0, value); 22
23 // 將元素插入到vector的任意位置
24
25 void insert(int i, const T &value) 將元素插入到i位置,i從0開始計算 26
27 void insert(int i, int count, const T &value) 從i位置開始插入count個T &value類型元素 28
29
30
31 // 刪除元素
32
33 QVector::iterator erase(QVector::iterator pos) 從vector中移除pos對應的元素 34
35 void remove(int i, int count) 從vector中移除從 i開始的count個元素 36
37 void pop_back() 刪除vector中最后一個元素 38
39 void pop_front() 刪除vector中第一個元素 40
41
42
43 // 改變i位置元素的值
44
45 void replace(int i, const T &value) 46
47
48
49 // 使用迭代器進行查找
50
51 QVector::iterator begin() 返回一個STL類型的迭代器指針指向vector的第一個元素 52
53 QVector::iterator end() 返回一個STL類型的迭代器指針指向vector的最后一個元素后面的假想元素 54
55 // capacity,reserve,count,length,size的比較
56
57 int capacity() const 返回vector客觀上的容量 58
59 void reserve(int size) 擴展至少size大小的內存 60
61 int count() const 返回vector中的元素個數 62
63 int length() const 等同於count() 64
65 int size() const 等同於count() 66
67
68
69 QVector::reference QVector::back() 返回vector中的最后一個元素的引用 等同於T &QVector::last() 70
71 T &QVector::front() 返回vector中的第一個元素的引用 等同於T & first() 72
73
74
75 void clear() 移除vector中的所有元素 76
77 bool empty() const 判斷vector是否為空,如果為空返回true,else返回false 78
79
80
81 int count(const T &value) const 返回T &value類型元素在vector中的個數 82
83 int indexOf(const T &value, int from=...) const 返回 value在vector中T &value類型元素的位置 84
85
86
87 const T &at(int i)const 返回 i位置元素 在vector的index 88
89 等同於 T QVector::value(int i) const