我想转换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);
Run Code Online (Sandbox Code Playgroud)
希望有帮助。
#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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
Lowercase of the string 'THIS TEXT!' is 'this text!'
Run Code Online (Sandbox Code Playgroud)