UnicodeString 到 char* (UTF-8)
我在 OS X 上使用 C++ 中的 ICU 库。我的所有字符串都是 UnicodeString,但我需要使用 fopen、fread 等系统调用。这些函数采用 const char* 或 char* 作为参数。我读到 OS X 在内部支持 UTF-8,所以我需要做的就是将 UnicodeString 转换为 UTF-8,但我不知道该怎么做。
UnicodeString 有一个 toUTF8() 成员函数,但它返回一个 ByteSink。我还找到了这些示例: http://source.icu-project.org/repos/icu/icu/trunk/source/samples/ucnv/convsamp.cpp 并阅读有关使用转换器的信息,但我仍然很困惑。任何帮助将不胜感激。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调用 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).ICU 用户指南 > UTF-8 提供了执行此操作的方法和描述。
并且现在不首选
extract()
。ICU User Guide > UTF-8 provides methods and descriptions of doing that.
And
extract()
is not prefered now.这将起作用:
This will work: