当前位置:网站首页>QT STL type iterator
QT STL type iterator
2022-06-29 06:55:00 【Mr.codeee】
1. brief introduction
STL Iterator and Qt and STL Compatible with native algorithms , And the speed is optimized ; For every container class , There are two STL Type iterators : One for read-only access , One for read-write access . It is recommended to use a read-only iterator when there is no need to modify the data , Because it's faster .
The following table is a summary of types :
| Container class | Read only iterator | Read write iterator |
|---|---|---|
| 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 |
The difference between defining read-only iterators and read-write iterators , They use different key words ,const_iterator Define a read-only iterator ,iterator Define read-write iterators .
Besides , You can also use const_reverse_iterator and reverse_iterator Define the corresponding inverse iterator .

STL An iterator of type is a pointer to an array , therefore “++” Operator causes the iterator to point to the next data item , Operator returns the contents of the data item .STL Iterators point directly to data items .
- begin() Point to the first data item of the container
- end() Is an invalid data item , End of the said
2. Example
Use QList Read only iterators traverse the output data .
QList<QString> list;
list << "1" << "2" << "3" << "4";
QList<QString>::const_iterator i;
for (i = list.constBegin(); i != list.constEnd(); ++i)
qDebug() << *i;Use QMap Read only iterators traverse the output data .
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 ();边栏推荐
- [c language] [sword finger offer article] - print linked list from end to end
- 开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
- try anbox (by quqi99)
- Move disassembly of exclusive delivery of script (the first time)
- JDBC connects to the database and socket sends the client.
- Qt 自定义位操作类
- 想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
- Fault: NetBt log for id4321
- Go basic data type conversion
- JDBC | Chapter 6: simple use of database connection pool
猜你喜欢

Differences between JSON objects and JSON strings

package.json的所有配置项及其用法,你都熟悉么

Failure: unable to log in to "taxpayer equity platform"

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事

Qt 程序打包发布-windeployqt工具

Hyperledger Fabric 2. X custom smart contract

Principle of screen printing adjustment of EDA (cadence and AD) software
![[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]](/img/a8/f77cc5e43e1885171e73f8ab543ee4.png)
[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]

Labor skills courses integrated into steam Education

How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)
随机推荐
'only_ full_ group_ The influence of by'sql mode on group by and its treatment
Subtotal of C language -- basic data types and their representations
关于端口转发程序的一点思考
Presto-Trial
Ribbon service invocation and load balancing
Vite快速上手
消息队列之通过队列批处理退款订单
Go basic data type conversion
Labor skills courses integrated into steam Education
Mongodb sort function
try anbox (by quqi99)
Move disassembly of exclusive delivery of script (the first time)
Are there too many programmers in China at present?
Some high-level usage of localstorage
Failure: unable to log in to "taxpayer equity platform"
QT (x): control operation
flutter配置国内镜像,连接真机
RPC and RMI
json tobean
Introduction to Ceres Quartet