对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
Having an issue with simple account checking program? Program returns compiling error that states "no match for 'operator||' unsure of how to fix?"
我是编程新手输入多个用户名和密码,匹配它们,还允许错误输入信息的人尝试再次输入。我已经写了以下程序来这样做。如果有人还可以阐明如何使程序允许重试的用户名/密码输入,而无需结束程序,那也将不胜感激。谢谢!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string username1="Varun";
string username2="Agne";
string username3="Geetha";
string username4="Mohan"; //Usernames for accounts
string pass1="PassworD";
string pass2="PASSWORD"; //Passwords for accounts
string pass3="password";
string pass4="Password";
string Uattempt; //User input for username
string Pattempt; //User input for password
cout << "Please enter your username.n";
cin >> Uattempt;
cout << "Please enter your password n"; //Asks for username and password entry by user
cin >> Pattempt;
if(Uattempt!=username1 || username2 || username3 || username4)
{
cout << "Access Denied. Incorrect username or password. Please retry.n"; //If username does not match possible entries, program will ask to retry
}
if(Pattempt !=(pass1||pass2)&&(pass3||pass4)
{
cout << "Access Denied. Incorrect username or password. Please retry.n"; //If password does not match possible entries, program will ask to retry
}
if (Uattempt&&Pattempt==username1&&pass1||username2&&pass2||username3&&pass3||username4&&pass4)
{
cout << "Access Granted. Welcome " + <<Uattempt<< + ".n";
}
else
{
return 0;
}
}
std :: string不定义||操作员。
更改以下内容:
if(Uattempt!=username1 || username2 || username3 || username4) ...
to:
if (Uattempt!=username1 || Uattempt!=username2 || Uattempt!=username3 || Uattempt!=username4) ...
使用
if(Uattempt != username1 && Uattempt != username2 && Uattempt != username3 && Uattempt != username4)
而不是
if(Uattempt!=username1 || username2 || username3 || username4)
如果您打算获取大量的用户名和密码图:
std::map<string, string> userandpass{
{"user1", "pass1"},
{"user2", "pass2"}};
string Uattempt, Pattempt;
std::cout << "Please enter your username.n";
std::cin >> Uattempt;
std::cout << "Please enter your password n"; //Asks for username and password entry by user
std::cin >> Pattempt;
auto userIt = userandpass.find(Uattempt);
if (userIt == userandpass.end())
{
std::cout << "Access Denied.";
return;
}
string &password = userIt->second;
if (password != Pattempt)
{
std::cout << "Access Denied.";
return;
}
std::cout << "Access Granted.";
相关文章:
- 错误消息:使用"string* +="后"no match for 'operator+='"
- 在 Eclipse: "error: no match for 'operator='" 中获取错误消息
- 如何'Invalid conversion'和'no match for operator'更正这些 c++ 错误
- 为什么当我没有变量或其他任何命名的东西时"no match for 'operator==' "错误?
- 如何修复以下错误"no match for call to '(std::tr1::shared_ptr<_iobuf*>) (FILE*&)'"
- 为什么我收到以下错误:"no match for 'operator=='"?(带模板的嵌套类)
- 在命名空间内的类中使用带有运算符重载的字符串流时"no match for ‘operator>>’"
- 提升::访客操作员过载的变体"Error: no match for call to [...]"
- 如何修复C++中的"no match for operator+"?
- 运算符重载错误"no match for operator error"
- "No match for operator []"
- 如果我没有重载,为什么我会"no match for ‘operator=’"自定义类?
- 为什么编译器显示错误"no match for 'operator[]' (operand types are 'carti' and 'int')"
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- "no match for 'operator >>'"代码中是什么意思?
- Valgrind Memcheck工具报告MISS MATCH delete for C ,但删除操作在另一个类/结
- "no match for ‘operator>>’ in ‘inputFile >> buffer"错误?
- 如何修复" no match for 'operator<<' in 'std::cout"错误?
- 简单迭代器差异的"No match for operator-"错误
- 使用 std::string 时"error: no match for ‘operator<<"