C++ String compare()Last Updated : 17 Mar 2025 This function compares the value of the string object to the sequence of characters specified by its parameter. Syntax :Suppose str1 and str2 are two strings and we want to compare these two strings then its syntax would look like:
Example 1Output: Both the strings are unequal Consider two strings str1 and str2. str1 contains value 'Hello' and str2 contains value 'javatpoint' ,We compare these two strings using compare method and this compare method always returns integer value.When we compare these two strings we get the value less than zero.Now,in this case 'if' condition fails then else statement will run and will print "Both the strings are unequal". Example 2Output: Strings are equal Next TopicC++ Strings |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India