C++相当于 PHP 在 Linux 中的utf8_decode函数

C++ equivalent of PHP's utf8_decode function in Linux

本文关键字:utf8 decode 函数 中的 Linux 相当于 PHP C++      更新时间:2023-10-16

可能的重复:
C &Boost:Encode/decode UTF-8

我需要将带有UTF-8编码文本的wstring转换为(错误地)中的新校正WSTRING。

PHP的ut8_decode功能可以完美处理。我也可以通过ICONV进行操作:

来自:

# cat wtf  | grep 1856 | awk '{print $2}'
å°ç³å·ãçç¾

to:

#cat wtf  | grep 1856 | awk '{print $2}'| iconv -f utf8 -t ISO-8859-1
小石川 玉美

在C#中,我能够以:

获得这种行为
public static string Utf8Decode(string utf8me) {
    return Encoding.UTF8.GetString(Encoding.GetEncoding(28591).GetBytes(utf8me));
}

我的大部分搜索都提出了特定于Windows的解决方法。由于我在Linux上,我认为我将要使用ICONV,但我不确定如何在C 中执行此操作。

iconv也是函数 iconv()

请参阅GLIBC文档:

  • http://www.gnu.org/software/libc/manual/html_node/generic-charset-conversion.html
  • http://www.gnu.org/software/libc/manual/html_node/iconv-examples.html