Windows Unicode C++ Stream Output Failure

前端 未结 4 1681
悲&欢浪女
悲&欢浪女 2020-11-30 09:27

I am currently writing an application which requires me to call GetWindowText on arbitrary windows and store that data to a file for later processing. Long story short, I no

4条回答
  •  半阙折子戏
    2020-11-30 09:43

    I just tested GCC (versions 4.4 thru 4.7) and MSVC 10, which all exhibit this problem.

    Equally broken is wprintf, which does as little as the C++ stream API.

    I also tested the raw Win32 API to see if nothing else was causing the failure, and this works:

    #include 
    int main()
    { 
        HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
        DWORD n;
        WriteConsoleW( stdout, L"\u03B2", 1, &n, NULL );
    }
    

    Which writes β to the console (if you set cmd's font to something like Lucida Console).

    Conclusion: wchar_t output is horribly broken in both large C++ Standard library implementations.

提交回复
热议问题