How to convert std::string to lower case?

后端 未结 26 2090
旧时难觅i
旧时难觅i 2020-11-22 00:01

I want to convert a std::string to lowercase. I am aware of the function tolower(), however in the past I have had issues with this function and it

26条回答
  •  萌比男神i
    2020-11-22 00:21

    I tried std::transform, all i get is abominable stl criptic compilation error that only druids from 200 years ago can understand (cannot convert from to flibidi flabidi flu)

    this works fine and can be easily tweaked

    string LowerCase(string s)
    {
        int dif='a'-'A';
        for(int i=0;i='A')&&(s[i]<='Z'))
                s[i]+=dif;
        }
       return s;
    }
    
    string UpperCase(string s)
    {
       int dif='a'-'A';
        for(int i=0;i='a')&&(s[i]<='z'))
                s[i]-=dif;
        }
       return s;
    }
    

提交回复
热议问题