输入用户名和用户密码,如果用户名不存在,或者密码错误,提示重新输入
#include <iostream>
#include <string>
using namespace std;
const string map[3][2] = {
"user1", "123455",
"user2", "asdfasdf",
"root", "password"
};
int main()
{
string name,pw;
int i;
while(cin >> name >> pw)
{
for(i = 0; i < 3; i ++)
{
if(map[i][0] == name)break;
}
if(i == 3) cout << "no such user name\n";
else if(map[i][1] != pw)
cout << "password error\n";
else break;
}
cout << "Login ok, welcome "<< name << endl;
cout << "no function, logout and exit\n";
return 0;
}
#include <string>
using namespace std;
const string map[3][2] = {
"user1", "123455",
"user2", "asdfasdf",
"root", "password"
};
int main()
{
string name,pw;
int i;
while(cin >> name >> pw)
{
for(i = 0; i < 3; i ++)
{
if(map[i][0] == name)break;
}
if(i == 3) cout << "no such user name\n";
else if(map[i][1] != pw)
cout << "password error\n";
else break;
}
cout << "Login ok, welcome "<< name << endl;
cout << "no function, logout and exit\n";
return 0;
}
温馨提示:答案为网友推荐,仅供参考