UnicodeString转换为char *(UTF-8) [英] UnicodeString to char* (UTF-8)

查看:66
本文介绍了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).

这篇关于UnicodeString转换为char *(UTF-8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆