mercredi 4 avril 2018

Why does == and .compare give different results here

This question here states that compare method is similar to == However using compare and == in the following code works differently.Contents of a and b variables are same and == satisfies the condition if(a==b) however using a.compare(b) does not satisfy the condition why is that ?

int main()
{
 std::string a="3";
 std::string b="3";
 if(a.compare(b))
 {
     std::cout << "Same";
 }
 else
 {
     std::cout << "different";
 }
}

Aucun commentaire:

Enregistrer un commentaire