0
내 텍스트 파일 ("UsernamePassword.txt")에 여러 줄의 사용자 이름과 암호가 있습니다. 2 줄 또는 3 줄의 사용자 이름과 암호를 사용하여 로그인을 시도하면 "유효하지 않은 사용자 이름 또는 암호"부분으로 연결됩니다. 사용자 이름과 비밀번호의 첫 번째 줄만 작동합니다.여러 텍스트 줄을 읽는 방법
여러 줄을 읽는 방법에 대한 제안이 있으십니까?
{
fstream inFile;
string user, pass, username, password;
int choice;
Logo();
cout << endl << endl << endl;
inFile.open("UsernamePassword.txt");
if (!inFile)
cout << "Unable to Open File";
else
{
while (username != user)
cout << endl << endl << endl;
cout << " Please enter username: ";
cin >> user;
cout << " Please enter password: ";
cin >> pass;
{
inFile >> username >> password;
if (user == username && pass == password)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout << "\t ****************************************** " << endl;
cout << "\t ** !!! Welcome to CherryLunch !!! ** " << endl;
cout << "\t ****************************************** " << endl;
cout<<endl<<endl<<endl<<endl<<endl;
system("pause");
system("cls");
MainMenu();
}
else
{
cout<<endl<<endl<<endl<<endl<<endl;
cout << "\t !!! Invalid Username or Password !!!" << endl<<endl;
cout << "\t *** Please try again ***" << endl;
cout<<endl<<endl<<endl<<endl<<endl;
system("pause");
system("cls");
}
}
}
inFile.close();
}
while 문을 잘못된 줄에 놓았습니까? 또한 텍스트 파일 스 니펫을 표시하십시오. – David
'while (username! = user)'한 줄을'cin >> pass; 아래로 한 줄 옮깁니다. 아마도 그것이 의도 한 일이라고 생각합니다. 그것은 비록 잘못된 것이 아닙니다. –
이것은 [여기에있는 다른 질문] (http://stackoverflow.com/questions/28185382/how-to-stop-a-while-loop)과 관련된 동일한 코딩 오류의 또 다른 증상입니다. 거기에 대한 좋은 대답은 여기에도 적용됩니다. –