converting to utf8?

Discussion in 'C++' started by whatdoineed2do@yahoo.co.uk, Jul 14, 2007.

  1. Guest

    hi,

    i've not done much i18n stuff before but i was wondering how, if given
    a string (encoded as russian or kanji mb) how i would get this
    converted to utf8. i'm working with forte compiler on solaris

    i've something like:

    const char* s = "...."; // some russian/kanji encoded
    locale l("en_US.UTF8");
    wstringstream cnv;
    cnv.imbue(l);
    cnv << s;
    cout << "orig='" << s << "'\nconverted='" << cnv.str() << "'" <<
    endl;

    but this doesnt work. can anyone give me some advise?

    thanks
    ray
    , Jul 14, 2007
    #1
    1. Advertising

  2. James Kanze Guest

    On Jul 14, 1:42 pm, wrote:

    > i've not done much i18n stuff before but i was wondering how, if given
    > a string (encoded as russian or kanji mb) how i would get this
    > converted to utf8. i'm working with forte compiler on solaris


    > i've something like:


    > const char* s = "...."; // some russian/kanji encoded
    > locale l("en_US.UTF8");
    > wstringstream cnv;
    > cnv.imbue(l);
    > cnv << s;
    > cout << "orig='" << s << "'\nconverted='" << cnv.str() << "'" <<
    > endl;


    > but this doesnt work. can anyone give me some advise?


    The locale is only used for conversion when writing to or
    reading from a file. A priori, you'll have to pass through
    wchar, and use two different locales (in fact, two different
    codecvt<wchar> facets).

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Jul 14, 2007
    #2
    1. Advertising

  3. Guest

    On 14 Jul, 12:42, wrote:
    > hi,
    >
    > i've not done much i18n stuff before but i was wondering how, if given
    > a string (encoded as russian or kanji mb) how i would get this
    > converted to utf8. i'm working with forte compiler on solaris
    >
    > i've something like:
    >
    > const char* s = "...."; // some russian/kanji encoded
    > locale l("en_US.UTF8");
    > wstringstream cnv;
    > cnv.imbue(l);
    > cnv << s;
    > cout << "orig='" << s << "'\nconverted='" << cnv.str() << "'" <<
    > endl;
    >
    > but this doesnt work. can anyone give me some advise?
    >
    > thanks
    > ray


    i managed to figure this out; using iconv(3C) -- this provides the
    codepage conversion that i needed
    , Jul 21, 2007
    #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. Replies:
    2
    Views:
    589
    Rohit Gupta
    Jun 20, 2005
  2. Replies:
    4
    Views:
    1,684
  3. Tejas
    Replies:
    1
    Views:
    615
    William Ahern
    Nov 14, 2007
  4. gry
    Replies:
    2
    Views:
    702
    Alf P. Steinbach
    Mar 13, 2012
  5. P

    Converting codepages to UTF8

    P, Mar 30, 2006, in forum: Perl Misc
    Replies:
    16
    Views:
    674
    Dr.Ruud
    Apr 2, 2006
Loading...

Share This Page