小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

QT中foreach()的使用方法

 GLL_ 2018-07-14
foreach()
?foreach(變量,容器)
?在qt中foreach是一個關(guān)鍵字 ,類似于c語言的for循環(huán)
?原文:
?The foreach Keyword
?If you just want to iterate over all the items in a container in order, you can use Qt's foreach keyword. The keyword is a Qt-specific addition to the C++ language, and is implemented using the preprocessor.
?Its syntax is: foreach (variable, container) statement. For example, here's how to use foreach to iterate over a QLinkedList<QString>:

?翻譯:

如果您只是想遍歷容器中的所有條目,那么您可以使用Qt的foreach關(guān)鍵字。關(guān)鍵字是對C++語言的一個特定于qt的添加,并且是使用預(yù)處理程序?qū)崿F(xiàn)的。

它的語法是:foreach(變量,容器)語句。例如,下面是如何使用foreach來迭代QLinkedList:
?QLinkedList<QString> list;
...
QString str;
foreach (str, list)
    qDebug() << str;

?
?原文:The foreach code is significantly shorter than the equivalent code that uses iterators:
?翻譯:foreach代碼比使用迭代器的等效代碼要短得多:
?QLinkedList<QString> list;
...
QLinkedListIterator<QString> i(list);
while (i.hasNext())
    qDebug() << i.next();

?原文:Unless the data type contains a comma (e.g., QPair<int, int>), the variable used for iteration can be defined within the foreach statement:
?翻譯:除非數(shù)據(jù)類型包含一個逗號(例如,QPair<int,int),否則用于迭代的變量可以在foreach語句中定義:
?QLinkedList<QString> list;
...
foreach (const QString &str, list)
    qDebug() << str;
?
?原文:And like any other C++ loop construct, you can use braces around the body of a foreach loop, and you can use break to leave the loop:
?翻譯:就像任何其他C++循環(huán)結(jié)構(gòu)一樣,您可以在foreach循環(huán)的主體周圍使用牙套,您可以使用break來離開循環(huán):
?
QLinkedList<QString> list;
...
foreach (const QString &str, list) {
    if (str.isEmpty())
        break;
    qDebug() << str;
}
?例子:

QStringList slt = {"abc", "qwe", "upo"};
foreach(QString s , slt )
{
    cout<<s<<endl;
}
// 輸出結(jié)果為:
abc
qwe
upo


?

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多