You can create a predicate function and use it in std::equals to compare:
bool icompare_pred(unsigned char a, unsigned char b) { return std::tolower(a) == std::tolower(b); } bool icompare(std::string const& a, std::string const& b) { if (a.length()==b.length()) { return std::equal(b.begin(), b.end(), a.begin(), icompare_pred); } else { return false; } }
Now you can simply:
if (icompare(str1, str)) { std::cout << "Compares" << std::endl; }
source share