vector查找结构体实例find_if
2015-11-24 19:20
507 查看
</pre><pre name="code" class="cpp">
#include <iostream> #include <string> #include <functional> #include <list> #include <vector> #include <algorithm> using namespace std; typedef struct _tagSyncTable { int nType; //主表类型 string strName; //主数据表名 string strOrderBy; //排序方式 _tagSyncTable(int type, string name = "", string OrderBy = "") { nType = type; strName = name; strOrderBy = OrderBy; } _tagSyncTable(){} }SyncTable; //查找类 class FindType { public: bool operator()(SyncTable& dValue) { return dValue.nType == m_val.nType; } static void SetSyncTable(SyncTable dval) { m_val = dval; } private: static SyncTable m_val; }; SyncTable natvalue,destvalue; SyncTable FindType::m_val = natvalue; int main(int argc, char* argv[]) { vector <SyncTable> userList; SyncTable tempnat; SyncTable st; st.nType = 15; st.strName = "t_bas_ShopGoods"; st.strOrderBy = "GoodsId"; userList.push_back(st); st.nType = 16; st.strName = "t_bas_myCategory"; st.strOrderBy = "myCatId"; userList.push_back(st); st.nType = 17; st.strName = "t_pos_PresetGoods"; st.strOrderBy = "GoodsId"; userList.push_back(st); st.nType = 16; FindType::SetSyncTable(st); vector <SyncTable>::iterator it=find_if(userList.begin(), userList.end(), FindType()) ; if(it!=userList.end()) { SyncTable st = *it; cout << "Type=" << st.nType << '\t' << "Name=" << st.strName << '\t' << "OrderBy=" << st.strOrderBy << endl; } return 0; }
相关文章推荐
- 8635 气球
- redis cluster java client jedisCluster spring集成方法
- HDU1051Wooden Sticks
- javascript模块化编程二(AMD规范)
- python 装饰器
- 简单的单链表<实现单链表的增删查改逆序和寻找中间节点>
- IDEA在DEBUG模式下慢的问题
- Time to sail!
- 读《探索需求-设计前的质量》有感二
- 数据挖掘 之 关联规则求解算法Apriori的实现
- 原码, 反码, 补码 详解
- Laravel 5.1 超级大坑 CentOS 7 文件路径大小写敏感造成的Migrate异常
- HashMap与HashTable的区别、HashMap与HashSet的关系 t的关系
- javascript模块化编程一
- Activiti系列:带有serviceTask的或者定时启动任务的流程部署失败的原因分析
- 【学神-RHEL6.5】1-17 shell基础及if表达式
- I/O敏感指令
- python 从shell读取指定文件以及写入指定文件
- Android app优化策略
- Codeforces 505B __Mr. Kitayuta's Colorful Graph(floyd)