没有运算符"=="与这些操作数匹配

no operator "==" matches these operands

本文关键字:操作数 运算符      更新时间:2023-10-16

我不知道是什么原因造成的,但我认为这与功能"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;
}
password == password_checker

这是尝试在字符串和函数指针上调用operator==。你需要调用该函数,以便得到一个字符串:

password == password_checker()

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

else if部分它不应该等于、!=或只是else.

编译器

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

相关文章: