这读取文件的代码为什么只能读取文件中的第一行数据,取输入第二行时,就提示错误。
求大佬帮忙看看。
bool adlogon() //管理员登录
{
string name;
string password;
cout<<"请输入用户名名称: ";
cin>>name;
cout<<"请输入密码:";
cin>>password;
ifstream ifs("图书管理员名单.txt");
if(!ifs.is_open())
{
cout<<"文件打开失败"<<endl;
return 0;
}
string line;
while (getline(ifs, line))
{
size_t pos = line.find(' ');
string savedUsername = line.substr(0, pos);
string savedPassword = line.substr(pos + 1);
if (savedUsername == name && savedPassword == password)
{
cout << "Login successful!" << endl;
ifs.close();
home03();
return true;
}
else
{
system("cls");
cout<<"密码错误"<<endl;
adlogon();
}
}
}