#include
#include
#include
#include
class PERSON {
public:
size_t m_no;
std::string m_name;
public:
PERSON(size_t no, const char* name)
{
m_no = no;
m_name = name;
}
int operator==(const PERSON& p) const
{
return (p.m_no == m_no && p.m_name == m_name);
}
};
typedef std::list
typedef std::list
int get_random(size_t lo, size_t hi)
{
return (int)((double)rand() /
((double)RAND_MAX + 1) * (++hi - lo) + lo);
}
int main()
{
PersonList list;
srandom(getpid() * time(0));
for (size_t i=0; i<10; i++)
{
list.push_back(PERSON(get_random(1, 100), "ddd"));
}
printf("orig...\n");
PersonListIt it = list.begin();
while (it != list.end())
{
PERSON& p = *it;
printf("no:%d name:%s\n", p.m_no, p.m_name.c_str());
it++;
}
PersonListIt findIt = find(list.begin(), list.end(), PERSON(4, "ddd"));
if (findIt != list.end())
{
printf("found...\n");
}
return 0;
}
orig...
no:14 name:ddd
no:54 name:ddd
no:12 name:ddd
no:70 name:ddd
no:100 name:ddd
no:43 name:ddd
no:43 name:ddd
no:37 name:ddd
no:63 name:ddd
no:64 name:ddd
위 예제는, std::list에 PERSON이라는 객체를 집어넣고
find을 이용해서 찾는 예제입니다.
댓글 없음:
댓글 쓰기