How to convert std::string to lower case?

后端 未结 26 1672
旧时难觅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条回答
  •  迷失自我
    2020-11-22 00:20

    C++ doesn't have tolower or toupper methods implemented for std::string, but it is available for char. One can easily read each char of string, convert it into required case and put it back into string. A sample code without using any third party library:

    #include
    
    int main(){
        std::string str = std::string("How IS The Josh");
        for(char &ch : str){
            ch = std::tolower(ch);
        }
        std::cout<

    For character based operation on string : For every character in string

提交回复
热议问题