|
현정환 님이 쓰신 글 :
: 오늘은 제법 쌀쌀하네요..
:
: 모두 감기 조심하십시오..
:
: 질문은
:
: struct slave{
: int a;
: int b;
: int c[5];
: }
:
vector<slave> s;
:
: 이럴때 s 중에서 a의 값이 5 인 놈을 찾고 검색하고 싶다면 어찌해야 하는지 잘 모르겠네요..
별도의 비교 함수 객체가 필요합니다.
struct slave_a_eq_5
{
bool operator()(const slave& sl) { return sl.a == 5; }
};
위와 같이 정의한 후,
vector<slave>::iterator where = s.begin();
while((where = find_if(where, s.end(), slave_a_eq_5())) != s.end())
{
cout << where.b << endl;
}
또는
for (vector<slave>::iterator where = s.begin();
where != s.end();
where = find_if(where, s.end(), slave_a_eq_5())
{
cout << where.b << endl;
}
|