当前位置:网站首页>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 ();边栏推荐
- 分享 10 个 JS Promise 相关的面试题
- Analysis on the wave of learning robot education for children
- 2022.02.15
- Aging design guide for applets
- Annual inventory review of Alibaba cloud's observable practices in 2021
- Browser local storage
- 关于端口转发程序的一点思考
- Qt 自定义位操作类
- [deep learning] - maze task learning I (to realize the random movement of agents)
- Principle of screen printing adjustment of EDA (cadence and AD) software
猜你喜欢

Move disassembly of exclusive delivery of script (the first time)

Part 63 - interpreter and compiler adaptation (II)

MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory

分享 10 个 JS Promise 相关的面试题

Principle of screen printing adjustment of EDA (cadence and AD) software

RPC和RMI

力扣今日题-324. 摆动排序 II

Design and practice of kubernetes cluster and application monitoring scheme

How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli

Monitor employee turnover dynamics. This system makes employees tremble!
随机推荐
JDBC | Chapter 6: simple use of database connection pool
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- path width style function
Li Kou today's question -324 Swing sort II
Open source 23 things shardingsphere and database mesh have to say
Delete tag
融入STEAM教育的劳动技能课程
List集合实现分页
Why are keys unordered in golang map
Li Kou daily question - day 30 -1281 Difference of sum of bit product of integer
Hyperledger Fabric 2. X custom smart contract
更改主机名的方法(永久)
Some thoughts on port forwarding program
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]
Client and server working modes of JVM
RPC和RMI
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
try anbox (by quqi99)
Teach you how to develop your own NPM package (publish to the NPM official website)
VerilogA——计数器