Unicode support in C++0x

后端 未结 3 1621
太阳男子
太阳男子 2021-01-04 03:17

I\'m trying to use new unicode characters in C++0x. So I wrote sample code:

#include 
#include 
int main()
{
    std::u32string          


        
3条回答
  •  攒了一身酷
    2021-01-04 03:50

    When creating, the stream tries to obtain a 'codecvt' from the global locale, but fails to get one because the only standard codecvt's are for char and wchar_t. As a result, _M_codecvt member of the stream object is NULL. Later, during the attempt to output, your code throws an exception (not visible to user) in facet checking function in basic_ios.h, because the facet is initialized from _M_codecvt.

    Add a facet to the local associated with the stream to do the conversion from char32_t to the correct output. Imbue the stream with a locale containing a codecvt of the right type.

提交回复
热议问题