函数 towlower()
似乎在 Visual Studio 2012 中不起作用。这是一个示例:
#include <string>
#include <iostream>
#include <io.h>
#include <fcntl.h>
#include <wctype.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_U8TEXT);
wcout << (wchar_t)towlower(L'Я') << endl;
system("pause");
return 0;
}
字符保持大写。以前在这里问过类似的问题,但我找不到任何解决方案。
我可以使用另一种方法来更改为小写吗?
最佳答案
使用 tolower
的语言环境感知版本,但不要忘记也设置 C 语言环境。
例如:
#include <clocale>
#include <locale>
#include <iostream>
int main()
{
std::setlocale(LC_CTYPE, "");
std::wcout << L"The letter is: " << L'Я' << L" => "
<< std::tolower(L'Я', std::locale("")) << std::endl;
}
这打印:
The letter is: Я => я
在 iostream 中使用语言环境是一件棘手的事情,这背后隐藏着整个潘多拉魔盒。例如,您可以imbue 带有语言环境的流,并且您可以同时管理多个语言环境,特别是您可以为每个线程设置一个语言环境(这对于有状态的字符串编码转换可能是必需的)...有人应该写一本关于它的书(或者使用 Boost.Locale)。
关于c++ - 为什么 towlower() 函数不将 Я 转换为小写 я?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15889784/