Output unicode strings in Windows console app

后端 未结 11 1193
花落未央
花落未央 2020-11-21 11:20

Hi I was trying to output unicode string to a console with iostreams and failed.

I found this: Using unicode font in c++ console app and this snippet work

11条回答
  •  深忆病人
    2020-11-21 12:01

    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).

    Solution:

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

    Screenshot:

    Unicode in console

提交回复
热议问题