将unicode转换为char [英] convert unicode to char
问题描述
如何在 char * 或 char * const
http://www.embarcadero.com/rel =nofollow> embarcadero c ++?
How can I convert a Unicode string to a char*
or char* const
in embarcadero c++ ?
推荐答案
Unicode字符串真的不够具体到足以知道你的源数据是什么,但你可能意味着'UTF-16字符串存储为wchar_t数组',因为这是大多数人不知道正确的术语使用。
"Unicode string" really isn't specific enough to know what your source data is, but you probably mean 'UTF-16 string stored as wchar_t array' since that's what most people who don't know the correct terminology use.
char *也不足以知道你想要定位什么,虽然也许embarcadero有一些约定。
"char*" also isn't enough to know what you want to target, although maybe "embarcadero" has some convention. I'll just assume you want UTF-8 data unless you mention otherwise.
此外,我将我的示例限制为VS2010中的工作
Also I'll limit my example to what works in VS2010
// your "Unicode" string
wchar_t const * utf16_string = L"Hello, World!";
// #include <codecvt>
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t> convert;
std::string utf8_string = convert.to_bytes(utf16_string);
这假定wchar_t字符串是UTF-16,如Windows上的情况,代码。
This assumes that wchar_t strings are UTF-16, as is the case on Windows, but otherwise is portable code.
这篇关于将unicode转换为char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!