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

你。 提交于 2019-11-30 04:45:41

问题


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 and WIN32_FIND_DATA instead of the -W and -A versions and so on.

Now I want to have std::strings which change between std::string and std::wstring according to the unicode setting. Is that possible? Otherwise, this will probably end up getting extremely complicated.


回答1:


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;


来源:https://stackoverflow.com/questions/6132753/automatically-change-between-stdstring-and-stdwstring-according-to-unicode-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!