【问题标题】:no operator "==" matches these operands没有运算符 "==" 匹配这些操作数
【发布时间】:2013-12-22 09:09:48
【问题描述】:

我不知道是什么原因造成的,但我认为这与 函数“password_checker”??

这是我的代码:

#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

string password_checker();

int main()
{
string password;
cout << "please enter your password: " << endl;
cin >> password;
if (password == password_checker)
{
    cout << "Access granted" << endl;
}
else if (password == password_checker)
{
    cout << "Access denied" << endl;
}
Sleep(15000);
return 0;
}   

string password_checker()
{
string password = "123456";
return password;
}

【问题讨论】:

    标签: c++ operands


    【解决方案1】:
    password == password_checker
    

    这是试图在一个字符串和一个函数指针上调用operator==。您需要调用该函数以便获得一个字符串:

    password == password_checker()
    

    【讨论】:

      【解决方案2】:

      你应该调用函数:password_checker()。

      在else if 部分,它不应该等于!=,或者只是else。

      【讨论】:

        【解决方案3】:

        编译器认为,符合 if (password == password_checker) 您正在尝试查看密码变量和 password_checker 函数是否相同。您必须调用该函数:password_checker()。

        【讨论】:

          猜你喜欢
          • 2013-01-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-07
          • 2018-05-02
          相关资源
          最近更新 更多