Case-Insensitive String Comparison in C++ Last Updated : 18 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, strings are sequences of characters that are used to store text data which can be in both uppercase and lowercase format. In this article, we will learn how we can compare two case-insensitive strings in C++. Example: Input: string1 = "WELCOME TO GEEKS FOR GEEKS"string2 = "welcome to geeks for geeks"Output:Strings are equalCase-Insensitive String Comparison in C++To compare two case-insensitive strings in C++, we have to temporarily convert both strings to either lowercase or uppercase. After that, we can compare them to get the result which will not depend upon the case of the characters. ApproachCheck if the lengths of both the strings are equal or not. If not return false.Iterate through each character of both strings.Convert each character to lowercase format using std::tolower method.If any character is different return false.If all characters were same return true.C++ Program for Case-Insensitive String ComparisonThe following program illustrates how we can compare two case-insensitive strings in C++: C++ // C++ Program to illustrate how we can compare two // case-insensitive strings #include <cctype> #include <iostream> #include <string> using namespace std; // Function to check if two case insensitive strings are // equal or not bool compareStrings(string& str1, string& str2) { if (str1.length() != str2.length()) return false; for (int i = 0; i < str1.length(); ++i) { if (tolower(str1[i]) != tolower(str2[i])) return false; } return true; } int main() { // Declare two strings string str1 = "WELCOME TO GEEKS FOR GEEKS"; string str2 = "welcome to geeks for geeks"; // Check if they are equal or not if (compareStrings(str1, str2)) cout << "Strings are equal" << endl; else cout << "Strings are not equal " << endl; return 0; } OutputStrings are equal Time complexity: O(N), where N denotes the length of the two strings.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Case-Insensitive String Comparison in C++ S sravankumar_171fa07058 Follow Improve Article Tags : C++ C++-Misc C++ cpp-strings C Pattern Programs CPP Examples +1 More Practice Tags : CPPcpp-strings Similar Reads std::string::compare() in C++ The string::compare() function in C++ is used to compare a string or the part of string with another string or substring. It is the member function of std::string class defined inside <string> header file. In this article, we will learn how to use string::compare() in C++.The different ways to 4 min read LISP - Comparison Operators on Characters & Strings The contents of a field are compared to the contents of another field or a constant using Comparison operators. In Simple words, comparator operators are used to compare whether the two or more different values are equal or not. Comparison Operators on Character: Characters are not supported by num 3 min read Char Comparison in C Char is a keyword used for representing characters in C. Character size in C is 1 byte. There are two methods to compare characters in C and these are: Using ASCII valuesUsing strcmp( ) .1. Using ASCII values to compare characters The first method is pretty simple, we all know that each character ca 3 min read Comparing String objects using Relational Operators in C++ If strings are compared using relational operators then, their characters are compared lexicographically according to the current character traits, means it starts comparison character by character starting from the first character until the characters in both strings are equal or a NULL character i 2 min read C++ String Class and its Applications C++ string class and its applications have more functions as discussed in this article String vs Character Array In C++, in addition to a character array, there exists a similar kind of way to implement string, that is using a string class which is a part of C++ standard library.We need to add a hea 4 min read Like