Would std::basic_string be preferable to std::wstring on Windows?

后端 未结 3 2434
遇见更好的自我
遇见更好的自我 2021-02-20 13:36

As I understand it, Windows #defines TCHAR as the correct character type for your application based on the build - so it is wchar_t in UNICODE builds and char

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 13:59

    I have done this on very large projects and it works great:

    namespace std
    {
    #ifdef _UNICODE
        typedef wstring tstring;
    #else
        typedef string tstring;
    #endif
    }
    

    You can use wstring everywhere instead though if you'd like, if you do not need to ever compile using a multi-byte character string. I don't think you need to ever support multi byte character strings though in any modern application.

    Note: The std namespace is supposed to be off limits, but I have not had any problems with the above method for several years.

提交回复
热议问题