How to convert std::string to lower case?

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

    Boost provides a string algorithm for this:

    #include 
    
    std::string str = "HELLO, WORLD!";
    boost::algorithm::to_lower(str); // modifies str
    

    Or, for non-in-place:

    #include 
    
    const std::string str = "HELLO, WORLD!";
    const std::string lower_str = boost::algorithm::to_lower_copy(str);
    

提交回复
热议问题