比较字符串对象等于向量中的元素 所以我对C++很陌生,它让我有点心神不定。所以我需要帮助。我正在尝试搜索向量中的字符串对象,看看它们是否相等。正在搜索,我决定使用c++11 lamba表达式,因为它不断给我错误: Severity Code Description Project File Line Suppression State Error C3867 'User::getEmail': non-standard syntax; use '&' to create a pointer to member EmailServerClientApp c:\users\user\desktop\emailserverclientapp\emailserverclientapp\guinterface.cpp 110 Severity Code Description Project File Line Suppression State Error C2678 binary '==': no operator found which takes a left-hand operand of type 'overloaded-function' (or there is no acceptable conversion) EmailServerClientApp c:\users\user\desktop\emailserverclientapp\emailserverclientapp\guinterface.cpp 110 我创建了一个过载操作符(或者至少是我的C++知识,我想我确实这么做了)。看不出这有什么问题

比较字符串对象等于向量中的元素 所以我对C++很陌生,它让我有点心神不定。所以我需要帮助。我正在尝试搜索向量中的字符串对象,看看它们是否相等。正在搜索,我决定使用c++11 lamba表达式,因为它不断给我错误: Severity Code Description Project File Line Suppression State Error C3867 'User::getEmail': non-standard syntax; use '&' to create a pointer to member EmailServerClientApp c:\users\user\desktop\emailserverclientapp\emailserverclientapp\guinterface.cpp 110 Severity Code Description Project File Line Suppression State Error C2678 binary '==': no operator found which takes a left-hand operand of type 'overloaded-function' (or there is no acceptable conversion) EmailServerClientApp c:\users\user\desktop\emailserverclientapp\emailserverclientapp\guinterface.cpp 110 我创建了一个过载操作符(或者至少是我的C++知识,我想我确实这么做了)。看不出这有什么问题,c++,c++11,vector,lambda,comparison,C++,C++11,Vector,Lambda,Comparison,这是我的用户类: private: string userName; string password; string email; public: User(); User(string name, string pass, string e); void setUserName(string name); void setPassword(string pass); void setEmail(string e);

这是我的用户类:

    private:
    string userName;
    string password;
    string email;

public:
    User();
    User(string name, string pass, string e);

    void setUserName(string name);
    void setPassword(string pass);
    void setEmail(string e);
    bool numberInString(const std::string& s);
    void print()const;

    User &operator=(User other)
    {
        std::cout << "copy assignment of Email\n";
        std::swap(userName, other.userName);
        std::swap(password, other.password);
        std::swap(email, other.email);
        return *this;
    }
    friend bool operator ==(const User &c1, const string &e);



    string getUserName()const;
    string getPassword()const;
    string getEmail()const;

    ~User();
};
这个方法我试图在向量中找到实际的电子邮件:

bool checkIfUserExists(vector<User> v,string email, string password) {/* using c++11 lamba expression to find an 
                                                                      element in vector matching my string object 
                                                                      */
    vector<User>::iterator it = std::find_if(v.begin(), v.end(), [&email](const User&c1) {return c1.getEmail == email; });

        if (it != v.end())
        {
            return true;
        }
        else {
            return false;
        }
}
bool checkIfUserExists(vector v,string email,string password){/*使用c++11 lamba表达式查找
向量中的元素匹配我的字符串对象
*/
vector::iterator it=std::find_if(v.begin(),v.end(),[&email](const User&c1){return c1.getEmail==email;});
如果(it!=v.end())
{
返回true;
}
否则{
返回false;
}
}
我做错了什么。拜托,我需要帮助。很快就会哭的。先谢谢你

{return c1.getEmail == email;}
getEmail()
是类方法,而不是类成员。正确的语法应为:

{return c1.getEmail() == email;}

checkIfUserExists中没有任何错误,除了lambda中,您忘记了调用c1.getEmail()。哦,我的上帝。真不敢相信我已经看了几个小时了:(注意你可以使用你定义的
操作符==
,所以很简单:
it=std::find(v.begin(),v.end(),email)
!!!哦,我的天啊。现在要从屋顶上跳下去了。哈哈
{return c1.getEmail() == email;}