Visual c++ UTF-8到拉丁语(ISO-8859-1)在C+中的转换+; 我想知道如何编写代码,在C++中执行一个UTF-8到拉丁语(ISO-859-1)转换。

Visual c++ UTF-8到拉丁语(ISO-8859-1)在C+中的转换+; 我想知道如何编写代码,在C++中执行一个UTF-8到拉丁语(ISO-859-1)转换。,visual-c++,utf-8,character-encoding,iso-8859-1,Visual C++,Utf 8,Character Encoding,Iso 8859 1,以下网站不提供所需的转换: 插入值:úsername 提供的结果为:úsername 我有一段代码,它完成了前一篇文章中类似的工作,但似乎没有转换字符串 int utf8_to_unicode(std::deque<int> &coded) { int charcode = 0; int t = coded.front(); coded.pop_front(); if (t < 128) { return t;

以下网站不提供所需的转换:

插入值:úsername

提供的结果为:úsername

我有一段代码,它完成了前一篇文章中类似的工作,但似乎没有转换字符串

int utf8_to_unicode(std::deque<int> &coded)
{
    int charcode = 0;
    int t = coded.front();
    coded.pop_front();
    if (t < 128)
    {
        return t;
    }
    int high_bit_mask = (1 << 6) -1;
    int high_bit_shift = 0;
    int total_bits = 0;
    const int other_bits = 6;
    while((t & 0xC0) == 0xC0)
    {
        t <<= 1;
        t &= 0xff;
        total_bits += 6;
        high_bit_mask >>= 1; 
        high_bit_shift++;
        charcode <<= other_bits;
        charcode |= coded.front() & ((1 << other_bits)-1);
        coded.pop_front();
    } 
    charcode |= ((t >> high_bit_shift) & high_bit_mask) << total_bits;
    return charcode;
}
int utf8到unicode(std::deque和coded)
{
int charcode=0;
int t=编码的.front();
编码为.pop_front();
if(t<128)
{
返回t;
}
int high_bit_mask=(1您需要来自
libiconv
的函数。
iconv
转换函数的第一个参数(部分
iconv\u t
)应该通过在程序初始化时获得,可能带有

 ic = iconv_open("ISO-8859-1","UTF-8");

(其中
ic
是一些静态或全局
iconv\u t
变量).

可能有用。@BasileStarynkevitch我正在寻找一种解决方案,在源代码中硬编码此转换IConv也是一个库。我不确定在源代码中硬编码此转换意味着什么。您不能配置用于源代码的文本编辑器(例如,
emacs
)要以想要的编码保存它?@BasileStarynkevitch请查看上面的代码以了解我要查找的内容