'for' loop vs Qt's 'foreach' in C++
问题 Which is better (or faster), a C++ for loop or the foreach operator provided by Qt? For example, the following condition QList<QString> listofstrings; Which is better? foreach(QString str, listofstrings) { //code } or int count = listofstrings.count(); QString str = QString(); for(int i=0;i<count;i++) { str = listofstrings.at(i); //Code } 回答1: It really doesn't matter in most cases. The large number of questions on StackOverflow regarding whether this method or that method is faster, belie