#pragma once
#include <string>
using namespace std;
class ci_char_traits :
public std::char_traits<char>
{
public:
static bool eq(char c1,char c2)
{
return toupper(c1)==toupper(c2);
}
static bool lt(char c1,char c2)
{
return toupper(c1)<toupper(c2);
}
static int compare(const char* s1,const char* s2,size_t n)
{
return _memicmp(s1,s2,n);
}
static const char* find(const char* s,int n,char a)
{
while(n-- > 0 && toupper(*s)!=toupper(a))
{
++s;
}
return n>0 ? s:0;
}
};
We can use the ci_char_traits class as thus:
basic_string<char,ci_char_traits> str1,str2;
str1="oK";
str2="ok";
if(str1==str2)
{
cout<<"ok"<<endl;
}
if(str1=="ok")
{
cout<<"ok"<<endl;
}
cout<<str1.c_str()<<endl;
return 0;