tolower函数用于C ++字符串 [英] tolower function for C++ strings
本文介绍了tolower函数用于C ++字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个内置函数将C ++字符串从大写字母转换为小写字母?如果不将它转换为cstring并且对每个char使用tolower是唯一的选择?
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 option ?
非常感谢你提前。
推荐答案
如果 boost
是一个选项:
#include <boost/algorithm/string.hpp>
std::string str = "wHatEver";
boost::to_lower(str);
否则,可以使用 std :: transform
:
std::string str = "wHatEver";
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
如果您有一些自定义区域设置感知,还可以使用另一个函数 tolower
。
You can also use another function if you have some custom locale-aware tolower
.
这篇关于tolower函数用于C ++字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文