C++: LPWSTR prints as an address in cout

后端 未结 1 420
一个人的身影
一个人的身影 2020-12-19 06:01

I have a variable of type LPTSTR, which I print to std::cout with <<. In an ANSI system (don\'t know exactly where it is determi

相关标签:
1条回答
  • 2020-12-19 06:43

    For Unicode strings you want wcout.

    You may be seeing hex because the ANSI/ASCII output stream doesn't know how to handle Unicode characters.

    LPTSTR and LPWSTR are actually C-isms inherited from the C Windows API days. For C++ I would strongly encourage you to use std::string and/or std::wstring instead.

    If you need to roll your own macro, you'll want something like:

    #ifdef _UNICODE
    std::wostream& COUT = std::wcout;
    #else
    std::ostream& COUT = std::cout;
    #endif
    
    0 讨论(0)
提交回复
热议问题