Error - String Compare
What's the problem with this string compare? It compiled, but it didn't do what I expected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
void password(){
string fpass;
string pass;
cout << "Type the password " << endl;
getline(cin,pass);
cin.ignore();
ifstream fin(FILENAME1);
string str;
getline(fin, str);
fpass = str;
cin.ignore();
if (pass.compare(fpass) == 0){
cout << " Hello!" << endl << endl;
cout << "What do you want to do?" << endl;
}else{
cout << "\n\n INCORRECT! \n \n \n";
cin.ignore();
char choice;
cout << "Try again? y/n --> ";
cin >> choice;
if (choice == 'y'){
password();
}
}
}
|
Print out the two strings so you can see what's being compared, or view them in a debugger.
Topic archived. No new replies allowed.