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

I am writing a DLL and want to be able to switch between unicode and multibyte settings in MSVC ++ 2010. For example, I use _T("string") and LPCTSTR and WIN32_FIND_DATA instead of versions -W and -A, etc.

Now I want to have std :: strings that change between std::string and std::wstring according to the unicode setting. Is it possible? Otherwise, it is likely to become extremely complex.

+6
source share
1 answer

Why not do it the way the Win32 API does: use wide characters inside and provide a personal converting facade of DoSomethingA functions that simply transform their input into Unicode.

Thus, you can define the type of tstring as follows:

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

or perhaps:

 typedef std::basic_string<TCHAR> tstring; 
+11
source

Source: https://habr.com/ru/post/889062/


All Articles