我已经编程了很多年,但对std
命名空间和std::string
类非常新。将char *转换为Unicode std :: string
我在写代码来读取Gdiplus::PropertyItem::value
的值,即char *
。
什么是最接受的方式来将此char *
值转换为string
,在我的情况下,这是一个Unicode字符串?
我已经编程了很多年,但对std
命名空间和std::string
类非常新。将char *转换为Unicode std :: string
我在写代码来读取Gdiplus::PropertyItem::value
的值,即char *
。
什么是最接受的方式来将此char *
值转换为string
,在我的情况下,这是一个Unicode字符串?
你提到string
但你说它是一个Unicode字符串。那么我想你的意思是wstring
。您可以使用MultiByteToWideChar函数在两者之间进行转换。事情是这样的:
std::string str(...);
int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstr(size, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
对不起,我已经习惯了MFC和'CString',这是ASCII或Unicode取决于构建设置。所以,是的,它看起来像我需要'std :: wstring'。但我很失望,我需要使用原始的Windows API,而'std :: wstring'在这里甚至不提供帮助。 –
@JonathanWood wstring vs string。看看http://stackoverflow.com/a/402918/1866301 –
看到http://utf8everywhere.org –