wchar_t -> UTF-8?

Discussion in 'C++' started by Jon Willeke, Feb 8, 2004.

  1. Jon Willeke

    Jon Willeke Guest

    This feels like a FAQ, but I've been unable to find a satisfactory
    answer. Given a Unicode encoding (such as UCS-4) in wchar_t, I want to
    convert to UTF-8 (or another locale-specific encoding) in a manner not
    entirely unlike the following:

    wstring w = L"H\xe9llo";

    locale loc( "en_US.UTF-8" );
    wcout.imbue( loc );
    wcout << w << endl;

    I've tried Visual C++ 6.0 and Borland C++ 5.6.4 on Windows, as well as
    GCC 3.3.1 on Linux. They don't seem to do anything approximately like
    this. I tried plugging in a hand-written codecvt subclass, but it
    doesn't seem to be used.
     
    Jon Willeke, Feb 8, 2004
    #1
    1. Advertising

  2. Jon Willeke

    John Ericson Guest

    "Jon Willeke" <> wrote in
    message news:pLxVb.8466$...
    > This feels like a FAQ, but I've been unable to find a

    satisfactory
    > answer. Given a Unicode encoding (such as UCS-4) in

    wchar_t, I want to
    > convert to UTF-8 (or another locale-specific encoding) in

    a manner not
    > entirely unlike the following:
    >
    > wstring w = L"H\xe9llo";
    >
    > locale loc( "en_US.UTF-8" );
    > wcout.imbue( loc );
    > wcout << w << endl;
    >
    > I've tried Visual C++ 6.0 and Borland C++ 5.6.4 on

    Windows, as well as
    > GCC 3.3.1 on Linux. They don't seem to do anything

    approximately like
    > this. I tried plugging in a hand-written codecvt

    subclass, but it
    > doesn't seem to be used.


    IIRC, Dinkumware has a library for various code conversions.
    You might want to Google a bit in comp.lang.c++ and
    comp.lang.c++.moderated, since there are some good threads
    in there on the various issues. Be prepared for some quirks,
    depending on your system. Best regards, JE
     
    John Ericson, Feb 8, 2004
    #2
    1. Advertising

  3. Tilman Kuepper, Feb 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton
    Replies:
    23
    Views:
    7,766
    Phlip
    Mar 12, 2006
  2. Replies:
    3
    Views:
    1,135
    James Kanze
    Aug 15, 2008
  3. Boris Du¹ek
    Replies:
    3
    Views:
    1,474
    Boris Du¹ek
    Nov 3, 2008
  4. Ersek, Laszlo

    Re: UTF-8 and wchar_t

    Ersek, Laszlo, Mar 2, 2010, in forum: C Programming
    Replies:
    3
    Views:
    1,866
    Ersek, Laszlo
    Mar 3, 2010
  5. Ersek, Laszlo

    Re: UTF-8 and wchar_t

    Ersek, Laszlo, Mar 2, 2010, in forum: C Programming
    Replies:
    1
    Views:
    422
    Mikko Rauhala
    Mar 3, 2010
Loading...

Share This Page