【问题标题】:Unicode problem with linux g++linux g++的Unicode问题
【发布时间】:2010-11-05 15:49:50
【问题描述】:

我的 Ubuntu 10.10 linux 下的 unicode 函数有问题。许多 unicode 函数无法正常工作。当我尝试以下简单代码时:

#include <wchar.h>

int main(int argc, char *argv[])
{
    wprintf(L"test %s %s %s\n",L"one",L"two",L"three");
    return 0;
}

使用g++编译(gcc版本4.4.5 Ubuntu/Linaro 4.4.4.-14ubuntu5)有如下结果:

test o t t

而不是预期:

test one two three

其他处理 unicode 字符串的函数也不能正常工作。我在 MS Windows 下开发的很多代码,这是我第一次尝试 linux 编程。

(同样的错误出现在我测试这个片段的两台 linux 机器上)

感谢您的任何建议。

【问题讨论】:

    标签: c++ gcc unicode


    【解决方案1】:

    您需要%ls,如wprintf(3) 手册页中所述。

    【讨论】:

    • 谢谢,它有帮助。我花了一小时的时间搜索我的应用程序中有什么问题;-(。在 MS Visual Studio 下,%s 也适用于 ansi 和 unicode。
    • man 是你的朋友。但是您可能必须先安装 manpages-dev 软件包或类似的软件包。
    • 谢谢。我已经安装了手册页,因为这不是我将应用程序移植到 linux 的第一个问题 ;-)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 2011-02-10
    相关资源
    最近更新 更多