将Unicode转换为C ++中的UTF-8 [英] Unicode to UTF-8 in C++
本文介绍了将Unicode转换为C ++中的UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了很多,但找不到任何东西:
I searched a lot, but couldn't find anything:
unsigned int unicodeChar = 0x5e9;
unsigned int utf8Char;
uni2utf8(unicodeChar, utf8Char);
assert(utf8Char == 0xd7a9);
是否存在一个实现与 uni2utf8 类似的东西的库(最好是boost)?
Is there a library (preferably boost) that implements something similar to uni2utf8?
推荐答案
Boost.Locale还具有编码转换的功能:
Boost.Locale has also functions for encoding conversions:
#include <boost/locale.hpp>
int main() {
unsigned int point = 0x5e9;
std::string utf8 = boost::locale::conv::utf_to_utf<char>(&point, &point + 1);
assert(utf8.length() == 2);
assert(utf8[0] == '\xD7');
assert(utf8[1] == '\xA9');
}
这篇关于将Unicode转换为C ++中的UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文