这个 while 循环永远不会结束。例如,当我输入错误的密码时,它会一遍又一遍地进入“密码错误”部分。
Logo();
inFile.open("UsernamePassword.txt");
if (!inFile)
cout << "Unable to Open File";
else
{
cout << endl << endl << endl;
cout << " Please enter username: ";
cin >> user;
cout << " Please enter password: ";
cin >> pass;
while (username != user)
{
inFile >> username >> password;
if (user == username && pass == password)
{
cout << endl;
cout << "Welcome to CherryLunch!" << endl;
system("pause");
system("cls");
MainMenu();
}
else
{
cout << endl;
cout << " Invalid Username or Password!" << endl << endl;
system("pause");
system("cls");
}
}
}
inFile.close();
while 循环是无限的,因为您永远不允许用户输入新密码或用户名。当if语句失败时,它将返回到循环头(在那里它仍然是错误的)并继续前进。
让用户有机会输入新的用户/通行证组合,然后循环仍然可以是有限的(假设用户最终提供了正确的凭据)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)