printing utf8 in glib

后端 未结 4 841
日久生厌
日久生厌 2021-02-14 19:11

Why utf8 symbols cannot be printed via glib functions?

Source code:

#include \"glib.h\"
#include 

int main() {
    g_print(\"марко\\n\");         


        
4条回答
  •  我寻月下人不归
    2021-02-14 19:21

    Usually it is not recommended to use anything other than ASCII inside text files. You should use tools like gettext in order to translate words from different languages. If this is out of the question then you should store your string in UTF-8 in your code.

    Try printing this one (it's the hexadecimal representation of your string):

    char hex_marco[]={0xD0, 0xBC, 0xD0, 0xB0, 0xD1, 0x80, 0xD0, 0xBA, 0xD0, 0xBE, 0};
    

    This works for me in printf (cannot test here with glib):

    #include 
    
    char hex_marco[]={0xD0, 0xBC, 0xD0, 0xB0, 0xD1, 0x80, 0xD0, 0xBA, 0xD0, 0xBE, 0};
    
    int main(void)
    {
        printf("%s\n",hex_marco);
        return 0;
    }
    

    Redirect the output to file and see it as UTF-8.

    Hope it helps.

提交回复
热议问题