Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: how to read a Unicode file with fstream?

36 views
Skip to first unread message

P.J. Plauger

unread,
May 25, 2004, 12:04:20 PM5/25/04
to
"ss" <anon...@discussions.microsoft.com> wrote in message
news:D37A849F-5D40-484F...@microsoft.com...

> pls see belowed:
>
> vector < string > ary;
> fstream fs;
>
> copy(istream_iterator< string>(fs),
> istream_iterator< string >(),
> back_inserter(ary));
>
> copy(ary.begin(), ary.end(),
> ostream_iterator< string>(cout, L"\r\n"));
>
> read a text and display it.
> now, i want to change it, to read a Unicode-Text file.
> i tried to do...like this
>
> vector < wstring > ary;
> wfstream fs;
>
> copy(istream_iterator< wstring, wchar_t >(fs),
> istream_iterator< wstring, wchar_t >(),
> back_inserter(ary));
>
> DWORD dwBeg = GetTickCount();
> copy(ary.begin(), ary.end(),
> ostream_iterator< wstring, wchar_t >(wcout, L"\r\n"));
>
> but, the result was too bad, i trace it, i found the wfstream used
mbstowcs function to convert the data to wide character, but, the file had
been a Unicode file!
> how to do?

Depends on what you mean by a Unicode file. I suspect you want one of:

UTF-8
UCS-2BE
UCS-2LE
UTF-16BE
UTF-16LE

If so, then see our CoreX add-on library -- there's an online reference
manual for it
at our web site. It has all these conversions, and then some.

HTH,

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


David Lowndes

unread,
May 25, 2004, 12:11:05 PM5/25/04
to
>but, the result was too bad, i trace it, i found the wfstream used mbstowcs function to convert the data to wide character, but, the file had been a Unicode file!
>how to do?

A unicode text file has a marker at the start that you probably need
to detect before you try reading the strings. See the "Byte-order
Mark" topic in MSDN.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq

Igor Tandetnik

unread,
May 25, 2004, 12:23:41 PM5/25/04
to
> read a text and display it.
> now, i want to change it, to read a Unicode-Text file.

See
http://groups.google.com/groups?threadm=3e1b5aea_1%40corp.newsgroups.com
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


0 new messages