Automatically change between std::string and std::wstring according to unicode setting in MSVC++?

前端 未结 1 495
醉酒成梦
醉酒成梦 2021-01-05 08:10

I\'m writing a DLL and want to be able to switch between the unicode and multibyte setting in MSVC++2010. For example, I use _T(\"string\") and LPCTSTR

相关标签:
1条回答
  • 2021-01-05 08:19

    Why not do like the Win32 API does: Use wide characters internally, and provide a character-converting facade of DoSomethingA functions which simply convert their input to Unicode.

    That said, you could define a tstring type like so:

    #ifdef _UNICODE
    typedef std::wstring tstring;
    #else
    typedef std::string tstring;
    #endif
    

    or possibly:

    typedef std::basic_string<TCHAR> tstring;
    
    0 讨论(0)
提交回复
热议问题