#include <algorithm>
#include <vector>
#include <string>
struct Customer
{
int id;
std::string name;
std::string city;
Customer( int _id, const char *_name, const char *_city )
: id( _id )
, name( _name )
, city( _city )
{
};
};
struct CompareCustomer
{
int num;
bool operator() ( Customer &customer ) const
{
return ( customer.id == num );
}
};
int _tmain( int argc, _TCHAR* argv[])
{
std::vector< Customer > arr;
arr.push_back( Customer( 2, "Kim", "Seoul" ) );
arr.push_back( Customer( 51, "Choi", "Busan" ) );
arr.push_back( Customer( 31, "Park", "Gyeonggi-do" ) );
CompareCustomer compare;
compare.num = 31;
std::vector< Customer >::iterator iter = std::find_if( arr.begin(), arr.end(), compare );
if( iter != arr.end() )
{
printf( "%s lives in %s\n", iter->name.c_str(), iter->city.c_str() );
}
return 0;
}