【问题标题】:How to get the unicode from a emoji in c++ or cocos2dx?如何从 C++ 或 cocos2dx 中的表情符号中获取 unicode?
【发布时间】:2018-12-29 10:18:51
【问题描述】:

如果我有一个类似“??????”的表情符号,在代码中是:

std::string emojiStr = "????";

在网站上,表格显示此表情符号的 unicode,如:“U+1F31E”

请教我如何从字符串“????”中获取此 unicode在 c++/cocos2dx 中?

【问题讨论】:

标签: c++ cocos2d-x


【解决方案1】:

首先,谢谢你的回答,谢夫!

我在https://en.cppreference.com/w/cpp/locale/codecvt中找到了例子,并写了一个我看到的愚蠢的方法。但它毕竟可以工作。

代码如下:

std::string EWUtils::emojiToStr(std::string str)
{
    std::ofstream(FileUtils::getInstance()->fullPathForFilename("text.txt")) << str;
    std::wifstream fin(FileUtils::getInstance()->fullPathForFilename("text.txt"));
    fin.imbue(std::locale("en_US.UTF-8"));

    std::string name;
    for (wchar_t c; fin >> c; )
    {
        __String* item = __String::createWithFormat("%x",c);
        name = name + item->_string + "-";
    }
    if (name.length() > 1) {
        name.pop_back();
    }
    return name;
}

我知道确实没有必要将字符串写入 txt 文件。但是如果示例是这样写的,我就照着做吧。

我真的是个初学者。如果有人有更好的方法,欢迎展示。

【讨论】:

    猜你喜欢
    • 2021-07-24
    • 1970-01-01
    • 2019-12-07
    • 2019-01-03
    • 1970-01-01
    • 2016-12-31
    • 2016-12-02
    • 2016-05-26
    • 2016-02-06
    相关资源
    最近更新 更多