UnicodeString转换为char *(UTF-8)
我正在OS X上的C ++中使用ICU库.我所有的字符串都是UnicodeStrings,但是我需要使用fopen,fread等系统调用.这些函数将const char *或char *作为参数.我已经了解到OS X内部支持UTF-8,所以我要做的就是将UnicodeString转换为UTF-8,但是我不知道该怎么做.
I am using the ICU library in C++ on OS X. All of my strings are UnicodeStrings, but I need to use system calls like fopen, fread and so forth. These functions take const char* or char* as arguments. I have read that OS X supports UTF-8 internally, so that all I need to do is convert my UnicodeString to UTF-8, but I don't know how to do that.
UnicodeString具有toUTF8()成员函数,但它返回ByteSink.我还找到了以下示例:http://source.icu-project.org/repos/icu/icu/trunk/source/samples/ucnv/convsamp.cpp 并了解如何使用转换器,但我仍然感到困惑.任何帮助将非常感激.
UnicodeString has a toUTF8() member function, but it returns a ByteSink. I've also found these examples: http://source.icu-project.org/repos/icu/icu/trunk/source/samples/ucnv/convsamp.cpp and read about using a converter, but I'm still confused. Any help would be much appreciated.
调用 UnicodeString :: extract(...)
提取为char *,将NULL传递给转换器以获取默认值转换器(位于您的操作系统将使用的字符集中).
call UnicodeString::extract(...)
to extract into a char*, pass NULL for the converter to get the default converter (which is in the charset which your OS will be using).