Compare string ignoring the case
#include <string>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cwctype>
using namespace std;
inline bool caseInsCharCompareN(char a, char b) {
return(toupper(a) == toupper(b));
}
bool caseInsCompare(const string& s1, const string& s2) {
return((s1.size( ) == s2.size( )) &&
equal(s1.begin( ), s1.end( ), s2.begin( ), caseInsCharCompareN));
}
int main( ) {
string s1 = "In the BEGINNING...";
string s2 = "In the beginning...";
if (caseInsCompare(s1, s2))
cout << "Equal!\n";
}
/*
Equal!
*/
Related examples in the same category