Compare function

what exactly compare is doing

@shiva57reddy
The compare( ) of string class defined in the header file < cstring > or < string.h > compares two strings and returns a value based on that comparison.
This value is 0 , if both the strings are equal
Value is >0 , if first string is greater than second string
Value is <0 , if first string is less than second string.

The comparisons are done character by character based on ASCII values.
Consider this example
string s1 = “abc”;
string s2 = “abcd”;
string s3 = “aaaaa”;
string s4 = “abc”;

cout << s1.compare(s4) << endl ;
// Prints 0 as both the strings are equal

cout << s1.compare(s2) << endl;
//Prints a value <0 as “abc” is less than “abcd” .

cout << s1.compare(s3) << endl;
//Prints a value >0 as “abc” is greater than “aaaaa” . Do not compare string lengths but compare the first character of s1 with first character of s3. Since they are same , compare the second character. Since the second char of s3 is less than s1 in terms of ASCII values , s3 is considered smaller than s1.

if compare is the predefined fuction,why are we defining compare funtion here again