int doctorLand()
{
system("cls");
char admin[20], password[20], passwordr[20] = { 0 };
int filelength = 0;//计算文件长度
ifstream fin;
fin.open("医生密码.txt", ios::in);
fin.seekg(0, ios::end);
filelength = fin.tellg();//求文件长
fin.seekg(0);//求出文件长度后指针需要归零
fin.read((char*)&passwordr, filelength);
fin.close();
//cout<<passwordr<<filelength<<endl;//测试读取内容
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 欢迎使用患者住院管理系统! |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
cout << endl;
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 请输入您的用户名: |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
cin >> admin; cout << endl;
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 密码: |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
cin >> password; int i = 0; int c;
while (1)
{
if ((admin[0] == 'D' || admin[0] == 'N') && (admin[1] * 100 + admin[2] * 10 + admin[3] >= 1 || admin[1] * 100 + admin[2] * 10 + admin[3] <= 500) && strcmp(password, passwordr) == 0)
{
cout << "\n\n\n\n\n\n\n";
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 欢迎登陆! |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
_getch(); c = 1;
break;
}
else
{
cout << "\n\n\n\n\n\n";
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 账号或密码错误! |" << endl;
cout << " | |" << endl;
cout << " | 您还有" << 2 - i << "次机会 |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
i++;
Sleep(1000);
system("cls");
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 欢迎使用患者住院管理系统! |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
cout << endl;
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 请输入您的用户名: |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
cin >> admin; cout << endl;
cout << " ====================================================" << endl;
cout << " | |" << endl;
cout << " | 密码: |" << endl;
cout << " | |" << endl;
cout << " ====================================================" << endl;
cin >> password;
if (i == 2) { break; }
}
}
int d; if (c == 1) {
if (admin[0] == 'D')d = 1;
if (admin[0] == 'N')d = 2;
}
return d;
}
亲爱的友友们,我的这个登陆系统一直显示登陆失败,是哪里出错了吗,文档里的医生密码和护士密码都是6个1,用D和N区分,谢谢
if ((admin[0] == 'D' || admin[0] == 'N') && (admin[1] * 100 + admin[2] * 10 + admin[3] >= 1 || admin[1] * 100 + admin[2] * 10 + admin[3] <= 500) && strcmp(password, passwordr) == 0)
这个对admin的判断很奇怪,你要注意,它是ascii,admin[1] * 100,如果你要得到数字,那么得 (admin[1] - '0') * 100,别的类似
在读取保存密码的txt文件的时候,有可能换行符或空格一并给读了出来,建议,passwordr这个前后去掉空格或换行符后,再去比对,第二种建议是把passwordr的长度和值都打印出来,看下是不是和用户输入的一致。
还有就是检查下大小写问题,有可能是大小写敏感导致的。
你判断一个数大于等于1或者它小于等于500,那么不是永远为真吗
还有,难道你不是一个账号对应一个密码吗,为什么密码只有一个
1.拓扑排序
2.佛洛依德算法
3.迪杰斯特拉算法
4.深度优先算法
5.广度优先算法
6.采用邻接数组的方式存储有向有权图