📜  元素的 cpp 迭代器 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:50.351000             🧑  作者: Mango

代码示例1
vector arr = { 6, 3, 5, 2, 8 };
vector::iterator itr = std::find(arr.begin(), arr.end(), elem);

if (itr != end(arr)) {
    cout << "Element " << elem << " is present at index " << distance(arr, itr) << " in the given array";
}
else {
    cout << "Element is not present in the given array";
}