我想了解为什么比较函数没有给我正确的结果?
据我的理解,如果两个字符串相同,它应该返回0!
据我的理解,如果两个字符串相同,它应该返回0!
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;
}
"hoge\n"
和"hoge"
这样的东西,而导致结果不正确的原因可能是输入有误。 - MikeCATstrcmp(password.c_str(), id)
,而要加上无意义的转换呢? - MikeCAT