i want to know how it works
Regarding compare function
@ranjan.prashant3655 hey,compare() is a public member function of string class. It compares the value of the string object (or a substring) to the sequence of characters specified by its arguments.
The compare() can process more than one argument for each string so that one can specify a substring by its index and by its length.
Return type : compare() returns an integer value rather than a Boolean value.
Here is syntax:
int string::compare (string str)
Returns:
0 : if both strings are equal.
A value < 0 : if *this is shorter than str or,
first character that doesn’t match is smaller than str.
A value > 0 : if *this is longer than str or,
first character that doesn’t match is greater
this refer to string which called this function.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.