Skip to content

Win32下UTF8输入为char*时为乱码 #119

@Leadrive

Description

@Leadrive
CAAlertView *alertView = CAAlertView::createWithText(UTF8("提示"), UTF8("登陆成功"), UTF8("确定"), NULL);

这句在ios下是正常显示的。
如果改成char*
char* sTemp = "登陆成功";
std::wstring ws = utf8_to_unicode(sTemp);

CAAlertView *alertView = CAAlertView::createWithText(UTF8("提示"), unicode_to_utf8(ws.c_str()).c_str(), UTF8("确定"), NULL);

在ios下也是成功的。

但是在win32下却是乱码,原因是 _utf8_to_unicode 把四个汉字处理成了8个字节,在ios下是4个字节。建议在win32下,改用mbstowcs_s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions