首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

vector find_if的小疑点

2012-04-14 
vector find_if的小问题#includeiostream#include vector#includealgorithm#include stringusingn

vector find_if的小问题
#include   <iostream>
#include <vector>
#include   <algorithm>
#include <string>
using   namespace   std;
struct   test{
string   str1;
string   str2;
string   str3;
};
bool   findx(test   &zz)
{return   zz.str2== "name2 ";}
int   main()
{
vector <test> vv;

        test   aa;
vector <test> ::iterator   yy;
aa.str1= "1 ";
aa.str2= "name1 ";
aa.str3= "fine ";
vv.push_back(aa);
        aa.str1= "2 ";
aa.str2= "name2 ";
aa.str3= "fine ";
        vv.push_back(aa);
aa.str1= "3 ";
aa.str2= "name2 ";
aa.str3= "fine ";
        vv.push_back(aa);
        yy=find_if(vv.begin(),vv.end(),findx(vv));
return   0;
}

[解决办法]
yy=find_if(vv.begin(),vv.end(),findx(vv));
======================
yy=find_if(vv.begin(),vv.end(),findx);

热点排行