STL实现简单的忽略大小写字 符串比较

来源:互联网 发布:软件产品质量承诺 编辑:程序博客网 时间:2024/06/09 23:28

利用STL名字第二长的算法----lexicographical_compare


// 返回在忽略大小写的情况下c1是否在c2前面;

bool ciCharLess(char c1, char c2) {                                                               
                                                                
  tolower(static_cast<unsigned char>(c1)) <             
tolower(static_cast<unsigned char>(c2));       
}  

                                                             
bool ciStringCompare(const string& s1, const string& s2){
        return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),   
                                        ciCharLess);            
}


lexicographical_compare是strcmp的泛型版本

0 0
原创粉丝点击