How can I compare C- string with C++ string? -
i want find out why compare function doesn't give me correct result ?
as know should return 0 if 2 string same!
bool validatepassword(char id[], string password) { // cannot same id string if(password.compare(id) == 0) { cout << "password can not same id\n"; return false; } return true; }
as matteo italia mentioned in answer's comment. use std::string's operator== this:
bool validatepassword(char id[], string password) { return password == id; } this function unnecessary because caller should call operator== directly instead.
Comments
Post a Comment