怎样反向遍历QList(C++风格),该怎么解决
怎样反向遍历QList(C++风格)
RT
如果是用STL,我会这样做:
但QT的容器类好像没有反向迭代器啊,那应该怎么办呢?
------解决方案--------------------
非要反向迭代么?
QList::end()
--i
------解决方案--------------------
for (QList<int>::iterator i = list.end(); i != list1.begin();)
{
qDebug() << *(--i);
}
RT
如果是用STL,我会这样做:
- C/C++ code
#include <iostream> #include <list> using namespace std; int main() { list<int> mylist; for(int i=0; i<10; i++) mylist.push_back(i); list<int>::reverse_iterator riter = mylist.rbegin(); for(; riter!=mylist.rend(); ++riter) cout << *riter << endl; return 0; }
但QT的容器类好像没有反向迭代器啊,那应该怎么办呢?
------解决方案--------------------
非要反向迭代么?
QList::end()
--i
------解决方案--------------------
for (QList<int>::iterator i = list.end(); i != list1.begin();)
{
qDebug() << *(--i);
}