问题描述
我正在编写一个DLL,希望能够在MSVC ++ 2010中的unicode和多字节设置之间切换.例如,我使用 _T("string")
和 LPCTSTR
和 WIN32_FIND_DATA
而不是-W和-A版本等等.
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.
现在,我想拥有std :: strings,它根据unicode设置在 std :: string
和 std :: wstring
之间变化.那可能吗?否则,这可能最终变得极其复杂.
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.
推荐答案
为什么不像Win32 API那样:在内部使用宽字符,并提供 DoSomethingA
函数的字符转换外观将他们的输入转换为Unicode.
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.
也就是说,您可以像这样定义 tstring
类型:
That said, you could define a tstring
type like so:
#ifdef _UNICODE
typedef std::wstring tstring;
#else
typedef std::string tstring;
#endif
或可能:
typedef std::basic_string<TCHAR> tstring;
这篇关于根据MSVC ++中的unicode设置自动在std :: string和std :: wstring之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!