[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: something wrong with wchar_t printing?
From: |
Johann Klammer |
Subject: |
Re: something wrong with wchar_t printing? |
Date: |
Thu, 03 May 2018 00:10:52 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0 |
On 05/02/2018 08:24 PM, folkert wrote:
>>> I wrote a question on stackoverflow regarding printing of std::wstring
>>> using ncurses
>>> (https://stackoverflow.com/questions/50118848/utf-8-stdwstring-ncurses ).
>>> I'm starting to believe the problem is in waddwstr.
>>>
>>> If I have a utf-8 string in "temp", then convert that to std::wstring
>>> using
>>> std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
>>> std::wstring wstr = converter.from_bytes(temp);
>>> then
>>> waddwstr(win, wstr.c_str());
>>> prints a space for CERTAIN special characters. An U+00E4 prints fine but an
>>> U+1F5E0 prints as a space.
>>> If I print them in utf-8 format using wprintw, they come out allright.
>>
>> What size is wchar on your box?
>
> It is
> /usr/include/curses.h:typedef unsigned short wchar_t;
>
>
> Folkert van Heusden
>
I've been asking, because here I tried:
#include <stdio.h>
#include <wchar.h>
int main(int argc,char *argv[])
{
printf("%d\n",sizeof(wchar_t));
}
and got 4.
(the typedef in curses.h is #if 0 here..)
I am taking your example that you are trying to convert to utf16,
but believe wchar may be utf32 on linux.
you could try mbtowc() and similar from stdlib.h.