您的位置:首页 > 其它

STL中find函数

2015-09-05 16:21 483 查看
find声明:

[cpp]
view plaincopyprint?

template<class InputIterator, class Type>
InputIterator find(
InputIterator _First,
InputIterator _Last,
const Type& _Val
);
示例:

[cpp]
view plaincopyprint?

void test_find()
{
std::list <int> L;
std::list <int>::iterator Iter;
std::list <int>::iterator result;

L.push_back(40);
L.push_back(20);
L.push_back(10);
L.push_back(30);
L.push_back(10);

std::copy(L.cbegin(), L.cend(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;

result = std::find(L.begin(), L.end(), 10);
if (result == L.end())
std::cout << "There is no 10 in list L.";
else {
std::cout << "There is a 10 in list L";
if (++result != L.end())
std::cout << " and it is followed by a " << *result << ".";
}
std::cout << std::endl;
}

转自:/article/7701907.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: