📜  在对象向量中查找成员变量 cpp - C++ 代码示例

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

代码示例2
//Using a lambda function (only C++11 or newer)
std::vector v = ....;
std::string myString = ....;
auto it = find_if(v.begin(), v.end(), [&myString](const Type& obj) {return obj.getName() == myString;})

if (it != v.end())
{
  // found element. it is an iterator to the first matching element.
  // if you really need the index, you can also get it:
  auto index = std::distance(v.begin(), it);
}