且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Windows 控制台应用程序中输出 unicode 字符串

更新时间:2022-06-26 06:09:28

我在这里使用 Visual Studio 2010 验证了一个解决方案.通过这个 MSDN 文章MSDN 博客文章.诀窍是对 _setmode(..., _O_U16TEXT) 的模糊调用.

I have verified a solution here using Visual Studio 2010. Via this MSDN article and MSDN blog post. The trick is an obscure call to _setmode(..., _O_U16TEXT).

解决方案:

#include <iostream>
#include <io.h>
#include <fcntl.h>

int wmain(int argc, wchar_t* argv[])
{
    _setmode(_fileno(stdout), _O_U16TEXT);
    std::wcout << L"Testing unicode -- English -- Ελληνικά -- Español." << std::endl;
}

截图: