#include#include int main() { std::string str1 = "Hello"; std::string str2 = "Hello"; int result = str1.compare(str2); if (result == 0) { std::cout << "The two strings are equal" << std::endl; } else { std::cout << "The two strings are not equal" << std::endl; } return 0; }
#includeIn this example, we are comparing two strings "apple" and "banana" using the compare function. The function returns a value greater than 0 which indicates that the first string "apple" is greater than the second string "banana". The string compare function is part of the C++ standard library and does not require any additional packages or libraries to be installed.#include int main() { std::string str1 = "apple"; std::string str2 = "banana"; int result = str1.compare(str2); if (result > 0) { std::cout << "The first string is greater than the second string" << std::endl; } else { std::cout << "The first string is less than or equal to the second string" << std::endl; } return 0; }