problem about wofstream

Discussion in 'C++' started by mimi, Mar 30, 2007.

  1. mimi

    mimi Guest

    With a wofstream, we can input wstring into a file. But when i input
    some wide character of chinese characters into a file, some error
    occur.
    With the implementation of STLport 4.62, the wstring of chines
    characters were written to the file; But with the implementation of
    MS, that is both in VC6.0 and Visual Studio 2005, noting was written
    to the file.I don't know why and I wonder to know what the C++
    standard said about this? What does the standard guarantees while
    dealing with unicode characters?Where could I find such information?
    Thanks for any advice.
    #include <fstream>

    int main()
    {
    std::wofstream strm2("test.txt");
    strm2 << L"ÎÒ°®±±¾©Ìì°²ÃÅ";

    return 0;
    }
    mimi, Mar 30, 2007
    #1
    1. Advertising

  2. mimi

    Guest

    On Mar 30, 2:47 pm, "mimi" <> wrote:
    > With a wofstream, we can input wstring into a file. But when i input
    > some wide character of chinese characters into a file, some error
    > occur.
    > With the implementation of STLport 4.62, the wstring of chines
    > characters were written to the file; But with the implementation of
    > MS, that is both in VC6.0 and Visual Studio 2005, noting was written
    > to the file.I don't know why and I wonder to know what the C++
    > standard said about this? What does the standard guarantees while
    > dealing with unicode characters?Where could I find such information?
    > Thanks for any advice.
    > #include <fstream>
    >
    > int main()
    > {
    > std::wofstream strm2("test.txt");
    > strm2 << L"ÎÒ°®±±¾©Ìì°²ÃÅ";
    >
    > return 0;

    I think u should call strm2.close() before return 0,and i find it can
    good work.
    , Mar 30, 2007
    #2
    1. Advertising

  3. On Mar 30, 1:47 pm, "mimi" <> wrote:
    > With a wofstream, we can input wstring into a file. But when i input
    > some wide character of chinese characters into a file, some error
    > occur.
    > With the implementation of STLport 4.62, the wstring of chines
    > characters were written to the file; But with the implementation of
    > MS, that is both in VC6.0 and Visual Studio 2005, noting was written
    > to the file.I don't know why and I wonder to know what the C++
    > standard said about this? What does the standard guarantees while
    > dealing with unicode characters?Where could I find such information?
    > Thanks for any advice.
    > #include <fstream>
    >
    > int main()
    > {
    > std::wofstream strm2("test.txt");
    > strm2 << L"我爱北京天安门";
    >
    > return 0;
    >
    > }


    The wide output streams in MSVC don't act as you would expect. The
    streams are not able to handle any characters outside the 0..255
    range.

    To do better you'll have to get different libraries, or write your own
    wrapper to do the translations for the formats you want to use.

    You may also find that you have problems with the source code if you
    drop those characters in like that too, but I admit to being unsure as
    to what text formats the compiler assumes or can read.


    K
    =?utf-8?B?S2lyaXQgU8OmbGVuc21pbmRl?=, Mar 30, 2007
    #3
  4. mimi

    P.J. Plauger Guest

    "Kirit Sælensminde" <> wrote in message
    news:...

    On Mar 30, 1:47 pm, "mimi" <> wrote:
    > With a wofstream, we can input wstring into a file. But when i input
    > some wide character of chinese characters into a file, some error
    > occur.
    > With the implementation of STLport 4.62, the wstring of chines
    > characters were written to the file; But with the implementation of
    > MS, that is both in VC6.0 and Visual Studio 2005, noting was written
    > to the file.I don't know why and I wonder to know what the C++
    > standard said about this? What does the standard guarantees while
    > dealing with unicode characters?Where could I find such information?
    > Thanks for any advice.
    > #include <fstream>
    >
    > int main()
    > {
    > std::wofstream strm2("test.txt");
    > strm2 << L"???????";
    >
    > return 0;
    >
    > }


    The wide output streams in MSVC don't act as you would expect. The
    streams are not able to handle any characters outside the 0..255
    range.

    [pjp] You're talking about the default codecvt facet, which has this
    limitation. The wide streams work fine.

    To do better you'll have to get different libraries, or write your own
    wrapper to do the translations for the formats you want to use.

    [pjp] Or get a better codecvt facet. See, for example, our Compleat
    Library add-on, which defines dozens.

    P.J. Plauger
    Dinkumware, Ltd.
    http://www.dinkumware.com
    P.J. Plauger, Mar 30, 2007
    #4
    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. std::wofstream

    , Sep 16, 2005, in forum: C++
    Replies:
    7
    Views:
    791
    P.J. Plauger
    Sep 18, 2005
  2. FNX
    Replies:
    11
    Views:
    1,123
    Pete Becker
    Jan 12, 2006
  3. jraul

    wofstream

    jraul, Jun 26, 2007, in forum: C++
    Replies:
    3
    Views:
    3,873
    Kevin Handy
    Jun 28, 2007
  4. Jeffrey Walton

    wstring, wofstream, and encodings

    Jeffrey Walton, Apr 12, 2008, in forum: C++
    Replies:
    8
    Views:
    906
    James Kanze
    Apr 13, 2008
  5. Ioannis Vranos

    wifstream/wofstream names

    Ioannis Vranos, Sep 30, 2008, in forum: C++
    Replies:
    1
    Views:
    707
Loading...

Share This Page