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. Advertisements

  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. Advertisements

  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. Advertisements

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. HNguyen
    Replies:
    4
    Views:
    2,676
    HNguyen
    Dec 21, 2004
  2. Laszlo Nagy
    Replies:
    6
    Views:
    945
  3. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    1,330
    Grzegorz ¦liwiñski
    Jan 19, 2011
  4. Krzysztof Fink-Finowicki via .NET 247

    Unicode and newline characters in XML text sond via Web Service

    Krzysztof Fink-Finowicki via .NET 247, Oct 17, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    192
    Krzysztof Fink-Finowicki via .NET 247
    Oct 17, 2004
  5. Krzysztof Fink-Finowicki via .NET 247

    Unicode and newline characters in XML text sond via Web Service

    Krzysztof Fink-Finowicki via .NET 247, Oct 31, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    266
    Dan Rogers
    Nov 15, 2004
  6. Krzysztof Fink-Finowicki via .NET 247

    Unicode and newline characters in XML text sond via Web Service

    Krzysztof Fink-Finowicki via .NET 247, Nov 17, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    251
    Krzysztof Fink-Finowicki via .NET 247
    Nov 17, 2004
  7. Ken Fine
    Replies:
    2
    Views:
    321
    Ken Fine
    Feb 5, 2004
  8. Constantin Gavrilescu
    Replies:
    5
    Views:
    223
    Carlos
    Sep 12, 2007
Loading...