小编Mis*_*ire的帖子

如何比较C字符串和C ++字符串?

我想找出为什么比较功能没有给我正确的结果?

据我所知,如果两个字符串相同,则应该返回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;
}
Run Code Online (Sandbox Code Playgroud)

c++ string c-strings

3
推荐指数
2
解决办法
3320
查看次数

标签 统计

c++ ×1

c-strings ×1

string ×1