In the C++ reference on string::compare, there is the following overload:
int compare ( size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2 ) const; which has two parameters n1 and n2 which in my eyes should always be equal or the function returns an int equal to true (string::compare return value of 0 (false) signifies equal strings). Is this correct? If not, could you provide an example showing a specific case where the comparison would be false if unequal lengths (n1 != n2) are compared?
Thanks!
intequal tofalse?intcan be easily converted to abool, this is how you can useifwithstrcmpand the like for example.strcmp,comparedoes not return a boolean value, but rather an integer (like it says). For equal stringscomparereturns an integer value of 0, which evaluates tofalsein boolean context.a.compare(b)nonetheless.a == b, thus I really feelcompareis better used when you actually care for ordering.