How to convert std::string to lower case?

后端 未结 26 1736
旧时难觅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:21

    Using range-based for loop of C++11 a simpler code would be :

    #include        // std::cout
    #include          // std::string
    #include          // std::locale, std::tolower
    
    int main ()
    {
      std::locale loc;
      std::string str="Test String.\n";
    
     for(auto elem : str)
        std::cout << std::tolower(elem,loc);
    }
    

提交回复
热议问题