zoukankan      html  css  js  c++  java
  • C++ / Qt 循环关键字 的明晰

        //简要介绍:
        /*
         * 使用C++和Qt大家都知道 循环的关键字C++有 for ,智能for, Qt 有foreach。
         * 用来循环QMap这种存放键值对的类型的时候,对于智能for和Qt的foreach的循环变量针对的是什么,小熊博士总是含糊,使用起来不清晰。
        */
    
        QMap<int, QString> map{{1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}};
        qDebug()<<"map is: "<<"QMap<int, QString> map{{1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}}-----
    
    ";
    
        //C++智能for
        qDebug()<<"C++智能for:";
        for (auto var : map){
            qDebug()<<var<<" ";
        }
    
        qDebug()<<"-----
    ";
        //qt 的 foreach
        qDebug()<<"qt 的 foreach:";
        foreach (auto var, map){
            qDebug()<<var<<" ";
        }
    //执行结果
    
    11:04:53: Starting E:Qt_projcetplayuild-play-Desktop_Qt_5_12_2_MinGW_64_bit-Debugdebugplay.exe...
    map is:  QMap<int, QString> map{{1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}}-----
    
    
    C++智能for:
    "one"  
    "two"  
    "three"  
    "four"  
    -----
    
    qt 的 foreach:
    "one"  
    "two"  
    "three"  
    "four"  
  • 相关阅读:
    POJ 3253 Fence Repair
    POJ 1328 Radar Installation
    bzoj 4010: [HNOI2015]菜肴制作
    bzoj 4008: [HNOI2015]亚瑟王
    UVA 1451 Average
    UVA 1481 Genome Evolution
    HDU 1542 Atlantis
    UVA 11419 SAM I AM
    UVA 11762 Race to 1
    P2209 [USACO13OPEN]燃油经济性Fuel Economy
  • 原文地址:https://www.cnblogs.com/azbane/p/12530393.html
Copyright © 2011-2022 走看看