I want to find out why compare function doesn't give me correct result ?
As I know it should return 0 if two string are the same!
bool validatePassword(char id[], string password) {
// cannot be the same as the id string
if(password.compare(id) == 0) {
cout << "password can not be as same as id\n";
return false;
}
return true;
}
As Matteo Italia mentioned in another answer's comment. Use the std::string's operator== like this:
bool validatePassword(char id[], string password) {
return password == id;
}
This function is really unnecessary because your caller should call operator== directly instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With