1、頭文件
#include <QVector>
2、使用格式
QVector<類型> 對象 例如: QVector<int> a; QVector<QString> b;
3、向容器中添加內容
a.append(1) a.append(2) a.insert(0, 3) //第一個參數代表的是插入數據的位置,第二個代表插入數據
4、循環打印容器內容
// 方式一 for(int i = 0; i < a.size(); i++){ qDebug() << a.at(i); } // 方式二 for(auto first = b.begin(); first != b.end(); first++){ qDebug() << *first; } // 方式三 QVector<int>::iterator iter; for (iter=b.begin();iter!=b.end();iter++){ qDebug() << *iter << "\0"; }
5、刪除元素
b.remove(1); // 參數代表的是位置 b.pop_back(); // 刪除末尾元素 b.pop_front(); // 刪除開始位置元素