Writing unicode characters to text file

Discussion in 'C++' started by Lex Syntax, Jun 21, 2011.

  1. Lex Syntax

    Lex Syntax Guest

    Hi,

    I wanted to write a unicode character, e.g \u1200, to a text file.
    Tried this but doesn't work:

    int main(int argc, char* argv[])
    {
    std::eek:fstream out("d:\\test.txt");
    out << "\u1200";
    out.close();
    return 0;
    }

    Any ideas?
     
    Lex Syntax, Jun 21, 2011
    #1
    1. Advertising

  2. Lex Syntax <> wrote:
    > I wanted to write a unicode character, e.g \u1200, to a text file.
    > Tried this but doesn't work:


    What do you mean "it doesn't work"? What is it exactly that you want to
    do. "Write a unicode character to a file" is not enough description to
    know what is it that you want.

    Unicode defines numerical values for characters. It doesn't define how
    those values are stored. There are ancillary standards that define how
    those values should be stored. Several ones. Most typical examples include
    the UTF-8 and the UTF-16 formats. (In theory you could also store them
    raw, which I suppose would be something akin to UTF-32, but even then
    you have the problem of specifying endianess.)

    If you want to store the unicode character eg. in UTF-8 format, you
    have to convert it. There's (currently) no functionality in standard C++
    to do this conversion, but you can use a third-party library such as
    http://utfcpp.sourceforge.net/
     
    Juha Nieminen, Jun 21, 2011
    #2
    1. Advertising

  3. Lex Syntax

    Lex Syntax Guest

    On Jun 21, 2:31 pm, Juha Nieminen <> wrote:
    > Lex Syntax <> wrote:
    > > I wanted to write a unicode character, e.g \u1200, to a text file.
    > > Tried this but doesn't work:

    >
    >   What do you mean "it doesn't work"? What is it exactly that you want to
    > do. "Write a unicode character to a file" is not enough description to
    > know what is it that you want.
    >
    >   Unicode defines numerical values for characters. It doesn't define how
    > those values are stored. There are ancillary standards that define how
    > those values should be stored. Several ones. Most typical examples include
    > the UTF-8 and the UTF-16 formats. (In theory you could also store them
    > raw, which I suppose would be something akin to UTF-32, but even then
    > you have the problem of specifying endianess.)
    >
    >   If you want to store the unicode character eg. in UTF-8 format, you
    > have to convert it. There's (currently) no functionality in standard C++
    > to do this conversion, but you can use a third-party library such ashttp://utfcpp.sourceforge.net/


    Thanks for the explanation and the url.
     
    Lex Syntax, Jun 21, 2011
    #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. Laszlo Nagy
    Replies:
    6
    Views:
    639
  2. Terry Reedy
    Replies:
    0
    Views:
    524
    Terry Reedy
    Jul 1, 2008
  3. M.-A. Lemburg
    Replies:
    0
    Views:
    902
    M.-A. Lemburg
    Jul 2, 2008
  4. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    985
    Grzegorz ¦liwiñski
    Jan 19, 2011
  5. Ken Fine
    Replies:
    2
    Views:
    204
    Ken Fine
    Feb 5, 2004
Loading...

Share This Page