Which tolower in C++?

前端 未结 3 986
小鲜肉
小鲜肉 2020-12-11 00:37

Given string foo, I\'ve written answers on how to use cctype\'s tolower to convert the characters to lowercase

transform(cbegin(foo         


        
3条回答
  •  甜味超标
    2020-12-11 01:18

    In the first case (cctype) the locale is set implicitely:

    Converts the given character to lowercase according to the character conversion rules defined by the currently installed C locale.

    http://en.cppreference.com/w/cpp/string/byte/tolower

    In the second (locale's) case you have to explicitely set the locale:

    Converts parameter c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent, as determined by the ctype facet of locale loc. If no such conversion is possible, the value returned is c unchanged.

    http://www.cplusplus.com/reference/locale/tolower/

提交回复
热议问题