How to use std::find/std::find_if with a vector of custom class objects?

If you are using C++0X you can use a simple lambda expression

std::string username = "Nicholas";    
std::find_if(userlist.begin(), userlist.end(), [username](Nick const& n){
    return n.username == username;
})

Leave a Comment