#include
#include
#include
#include
using namespace std;
bool older_than_20(int birthdate)
{
return (2016 - birthdate / 10000)>20;
}
int main()
{
maptable_item;//创建一个map类容器,用于存储名表
//创建名表
table_item["Charles"] = 19960207;
table_item["Sam"] = 19970130;
table_item["Michael"] = 19951213;
table_item["Benjamin"] = 19930516;
table_item["Kim"] = 19990315;
table_item["Jacob"] = 19970625;
table_item["Robinson"] = 19960322;
table_item["Lin"] = 19970331;
//输出名表
cout << "名表信息如下:\n";
map::const_iterator it;//创建一个不能修改所指向的元素的迭代器
for (it = table_item.begin(); it != table_item.end(); it++)//遍历容器
cout << it->first << ": " << it->second << endl;//输出元素的关键字和值
map::const_iterator ilocation;//创建一个不能修改所指向的元素的迭代器
ilocation =find_if(table_item.begin(),table_item.end(),older_than_20);//为什么这会报错
if (ilocation == table_item.end())
cout << "没有找到" << endl;
else
{
cout << "年龄大于20岁的人有:" << endl;
cout << ilocation->first << ": " << ilocation->second << endl;
}
system("pause");
return 0;
}