you don’t need use find
, please use find_if
, this is the link:http://www.cplusplus.com/reference/algorithm/find_if/
auto it = std::find_if( sortList.begin(), sortList.end(),
[&User](const std::pair<std::string, int>& element){ return element.first == User.name;} );
If you are using C++ standard before C++11, later, you’ll need a function instead of a lambda:
bool isEqual(const std::pair<std::string, int>& element)
{
return element.first == User.name;
}
it = std::find_if( sortList.begin(), sortList.end(), isEqual );