我想把 wstring
转换成小写。我发现有很多答案使用本地化信息。是否也有像 ToLower()
这样的函数适用于 wstring
?
std::towlower
是你想要的函数,它位于 <cwtype>
中。该头文件包含许多用于处理宽字符串的函数。
示例:
// Convert wstring to upper case
wstring wstrTest = L"I am a STL wstring";
transform(
wstrTest.begin(), wstrTest.end(),
wstrTest.begin(),
towlower);
#include <iostream>
#include <algorithm>
int main ()
{
std::wstring str = L"THIS TEXT!";
std::wcout << "Lowercase of the string '" << str << "' is ";
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
std::wcout << "'" << str << "'\n";
return 0;
}
输出:
Lowercase of the string 'THIS TEXT!' is 'this text!'
towlower('I') != 'i'
(实际结果为'ı'
)。 - Martin Bonner supports Monica