Qt: 访问容器(三种方法,加上for循环就四种了)good
#include <iostream>
#include <QString>
#include <QList>
#include <QListIterator>
int main(int argc, char *argv[]) {
QList<QString> list;
list << "One" << "Two" << "Three";
foreach(QString s, list) {
std::cout << s.toStdString() << std::endl;
}
QListIterator<QString> iter(list);
while (iter.hasNext()) {
std::cout << iter.next().toStdString() << std::endl;
}
QList<QString>::Iterator stlIter; // QList<QString>::iterator stlIter; // Ok
for (stlIter = list.begin(); stlIter != list.end(); ++stlIter) {
std::cout << stlIter->toStdString() << std::endl;
}
return 0;
}
http://www.cppblog.com/biao/archive/2008/03/21/45049.html