search详解(二)

2014-11-24 12:08:17 · 作者: · 浏览: 1
)));
}
有了第一个函数作为基础,第二个函数就容易理解多了.
需要注意的是,函数返回父迭代器.
举例:
template
bool equal_three( T _value1,T _value2 )
{
return_value1 == ++ _value2;
}
int main()
{
vectorvecInt;
vecInt.push_back( 2 );
vecInt.push_back( 5 );
vecInt.push_back( 7 );
vecInt.push_back( 3 );
vecInt.push_back( 5 );
vecInt.push_back( 4 );
vecInt.push_back( 5 );
vecInt.push_back( -17 );
vecInt.push_back( 3 );

listlstInt;
lstInt.push_back( 2 );
lstInt.push_back( 4 );
lstInt.push_back( 3 );
vector::iteratoriterFind = search(vecInt.begin(),vecInt.end(),lstInt.begin(),lstInt.end(),equal_three );
if (iterFind != vecInt.end() )
{
copy( iterFind,iterFind +lstInt.size(),ostream_iterator(cout," " ) );
}
cout<<"\n";
iterFind = search( vecInt.begin(),vecInt.end(),lstInt.begin(),lstInt.end());
if (iterFind != vecInt.end() )
{
copy( iterFind,iterFind +lstInt.size(),ostream_iterator(cout," " ) );
}
system( "pause");
return0;
}
3 5 4
请按任意键继续...



摘自 yuanweihuayan的专栏