用c++编写一个简单的用户登录程序

输入用户名和用户密码,如果用户名不存在,或者密码错误,提示重新输入

#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;
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网