当前位置:网站首页>Qt STL类型迭代器
Qt STL类型迭代器
2022-06-29 06:37:00 【Mr.codeee】
1.简介
STL迭代器与Qt和STL的原生算法兼容,并且进行了速度优化;对于每一个容器类,都有两个STL类型迭代器:一个用于只读访问,一个用于读写访问。无需修改数据时建议使用只读迭代器,因为速度更快。
下表为类型总表:
| 容器类 | 只读迭代器 | 读写迭代器 |
|---|---|---|
| QList<T>, QQueue<T> | QList<T>::const iterator | QList<T>::iterator |
| QLinkedList<T> | Q1. i nked List<1>: :const_iterator | QLinkedList<T>::iterator |
| QVector<T>, QStack<T> | QVector<T>::const_ilerator | QVector<T>::iterator |
| QSet<T> | QSet<T>::const_iterator | QSet<T>::iterator |
| QMap<Key, P> QMultiMap<Kcy, T> | QMap<Key, T>::const_iterator | QMap<Key, T>:: iterator |
| QHash<Key, T> QMultiHash<Key, T> | QHash<Key, T>: :const_iterator | QHash<Key, T>::iterator |
在定义只读迭代器和读写迭代器时的区别,它们使用了不同的关健字,const_iterator 定义只读迭代器,iterator 定义读写迭代器。
此外,还可以使用 const_reverse_iterator 和 reverse_iterator 定义相应的反反向迭代器。

STL 类型的迭代器是数组的指针,所以“++”运算符使迭代器指向下一个数据项,运算符返回数据项内容。STL 迭代器直接指向数据项。
- begin()指向容器的第一个数据项
- end()是无效的数据项,表示结束
2.示例
使用QList只读迭代器遍历输出数据。
QList<QString> list;
list << "1" << "2" << "3" << "4";
QList<QString>::const_iterator i;
for (i = list.constBegin(); i != list.constEnd(); ++i)
qDebug() << *i;使用QMap只读迭代器遍历输出数据。
QMap<int, int> map;
map[1] = 1;
map[2] = 2;
map[3] = 3;
QMap<int, int>::const_iterator i;
for (i = map.constBegin(); i != map.constEnd(); ++i)
qDebug () << i.key () << ':' << i.value ();边栏推荐
- 关于端口转发程序的一点思考
- How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli
- Client and server working modes of JVM
- 转:侯宏:企业数字化转型的关键不是技术,而是战略
- Chapter V online logic analyzer signaltap
- 百度小程序自动提交搜索
- JDBC | Chapter 5: closing and releasing JDBC connection resources
- Fault: KDC warning log for id29
- P5 DS - component and document Association
- Delete tag
猜你喜欢

UVM验证平台

Analytic hierarchy process

Annual inventory review of Alibaba cloud's observable practices in 2021

Redistemplate handles hash integer type problem resolution

融入STEAM教育的劳动技能课程

Qt 程序打包发布-windeployqt工具

Unity ar shadow shadow

Hyperledger Fabric 2. X custom smart contract

Labor skills courses integrated into steam Education

Games101 Lecture 10 geometry 1 Notes
随机推荐
Client and server working modes of JVM
Fault: administrator account cannot be selected for login
Service grid ASM year end summary: how do end users use the service grid?
Error: GPG check FAILED Once install MySQL
Analysis comp122 the Caesar cipher
JDBC连接数据库,socket发送客户端。
Chapter V online logic analyzer signaltap
IDEA常用插件
想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
Some thoughts on port forwarding program
力扣每日一题-第30天-1281.整数的各位积和之差
Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
Presto-Trial
Hyperledger Fabric 2. X custom smart contract
Output of character pointer to string in C language
What should I learn before learning programming?
Monitor employee turnover dynamics. This system makes employees tremble!
JDBC | Chapter 5: closing and releasing JDBC connection resources
Honeypot based on MySQL load data local INFILE
更改主机名的方法(永久)