QT c++ 使用谓词找出所有大于20的数

 

#include <vector>
using namespace std;

vector<int> v;
     
    v.push_back(10);
    v.push_back(20);
    v.push_back(30);
    v.push_back(40);
    v.push_back(50);

    //查找第一个大于20的数字
    //注意传入的是匿名函数,不是之前直接传入函数名
    vector<int>::iterator pos = find_if(v.begin(), v.end(), GreaterThan20());
    while (pos != v.end())
    {
        qDebug() << QString::number(*pos);
        //QThread::msleep(1000);
        ++pos;
    }

头文件添加:

 

posted @ 2024-12-31 08:58  txwtech  阅读(17)  评论(0)    收藏  举报