tolower function for C++ strings

前端 未结 6 976
误落风尘
误落风尘 2020-12-11 01:19

Is there an inbuilt function to convert C++ string from upper case letters to lowercase letters ? If not converting it to cstring and using tolower on each char is the only

6条回答
  •  囚心锁ツ
    2020-12-11 01:55

    If boost is an option:

    #include     
    
    std::string str = "wHatEver";
    boost::to_lower(str);
    

    Otherwise, you may use std::transform:

    std::string str = "wHatEver";
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    

    You can also use another function if you have some custom locale-aware tolower.

提交回复
热议问题