创建用户数据库错误"no match for 'operator==' in....." --C++
Creating User database error "no match for 'operator==' in....." --C++
我一直在命令提示符下处理用户数据库。它可以让你添加用户名和密码并登录。当我编译它时,我会得到错误no match for 'operator==' in
。我不太确定是什么原因导致的。而且,我已经将所有这些都存储在一个类中。
我的头文件是:
#ifndef USER_PSW_H
#define USER_PSW_H
#include <string>
class User_Psw
{
public:
User_Psw();
void addToDatabase();
void getNameIndex();
bool PasswordMatches();
void UserCheck();
protected:
private:
int sizeOfDatabase;
int index;
std::string Usernames;
std::string Password;
std::string username;
std::string password;
};
#endif // USER_PSW_H
构造函数是:
User_Psw::User_Psw()
{
const int SIZE = 100;
index = 0;
sizeOfDatabase = 0;
Usernames[SIZE];
Password[SIZE];
}
实际错误的函数为:
void User_Psw::getNameIndex()
{
for(int i=0; i < sizeOfDatabase; i++)
{
if (username == Usernames[i])
{
index = i;
}
}
}
包含错误的实际代码行为if (username == Usernames[i])
如果需要,我还可以添加更多的代码片段。
这不起作用,因为当您实际将类型定义为std::string
时,您访问Usernames
就像访问向量一样。
你想要这样的东西:
std::vector<std::string> Usernames;
然后你可以访问它像:
if (Usernames[i] == username) { // etc
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp