在MFC的CString中有CompareNoCase()接口可以方便的不区分大小写对比字符串,但std::string却没有,但可以使用std::equal()对比是否相同:
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iosfwd>
#include <iomanip>
using namespace std;
template<typename _Tp>
bool upperEqual(_Tp a, _Tp b)
{
return ((islower(a)?a-32:a) == (islower(b)?b-32:b) ) ? true : false;
}
int main()
{
//字符串不区分大小写
string l_strvalue("Test");
string l_strcmp("test");
if( l_strcmp = "tesst",l_strvalue.length() == l_strcmp.length() && equal( l_strvalue.begin(), l_strvalue.end(), l_strcmp.begin(), upperEqual<string::value_type> ))
cout<<"string is equal!"<<endl;
else cout<<"string is not equal!"<<endl;
return 0;
}