class Account
{
public:
string name,pw;
int i;
const string map[3][2];
Account()
{
const string map[3][2] = {
{"user1", "123455"},
{"user2", "asdfasdf"},
{"user3", "sb"}
};
}
void Login()
{
while(cin >> name >> pw)
{
for(i = 0; i < 3; i ++)
{
if(map[i][0] == name)break;
}
if(i == 3) cout << "用户名输入错误,请重新输入\n";
else if(map[i][1] != pw)
cout << "密码输入错误,请重新输入\n";
else break;
}
cout << "欢迎进入金拱门管理系统"<<"-----"<<name << endl;
}
void Goout()
{
while(cin >> name>>pw)
{
for(i = 0; i < 3; i ++)
{
if(map[i][0] == name)break;
}
if(i == 3) cout << "用户名输入错误,不能退出系统\n";
else if(map[i][1] != pw)
cout << "密码输入错误,不能退出系统\n";
else break;
}
cout<<"欢迎下次登陆金拱门管理系统"<<"-----"<<name<< endl;
}
};
你在Account()里面又定义了一个map,此map非彼map,作为成员变量的map还是没有初始化。
正确的代码如下:
// Q691800.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Account
{
public:
string name,pw;
int i;
string map[3][2];
Account()
{
map[0][0] = "user1";
map[1][0] = "user2";
map[2][0] = "user3";
map[0][1] = "123455";
map[1][1] = "asdfasdf";
map[2][1] = "sb";
}
void Login()
{
while(cin >> name >> pw)
{
for(i = 0; i < 3; i ++)
{
if(map[i][0] == name)break;
}
if(i == 3) cout << "用户名输入错误,请重新输入\n";
else if(map[i][1] != pw)
cout << "密码输入错误,请重新输入\n";
else break;
}
cout << "欢迎进入金拱门管理系统"<<"-----"<<name << endl;
}
void Goout()
{
while(cin >> name>>pw)
{
for(i = 0; i < 3; i ++)
{
if(map[i][0] == name)break;
}
if(i == 3) cout << "用户名输入错误,不能退出系统\n";
else if(map[i][1] != pw)
cout << "密码输入错误,不能退出系统\n";
else break;
}
cout<<"欢迎下次登陆金拱门管理系统"<<"-----"<<name<< endl;
}
};
int main()
{
Account acc;
acc.Login();
}
之前回答了很多lz的问题,但是都没有采纳,如果问题得到解决,麻烦点一个采纳,谢谢,要找之前的帖子,可以看这里
https://ask.csdn.net/my
if(map[i][0] == name) 和 if(map[i][1] != pw) 表达式不对,要用strcmp比较。
你的表达式不对,仔细修改