From: David Webber on
I am getting increasingly frustrated at the shortcomings of CStdioFile for
reading Unicode text files (unless I've missed something).

I've found a nice looking class on CodeProject
<http://www.codeproject.com/KB/files/textfiledocument.aspx> but it is
several years old.

Has something been introduced into MFC to do this sort of thing in the last
couple of Visual Studio releases? If not, is there something in the Win32
API or CRT?

Dave
--
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

From: Giovanni Dicanio on
"David Webber" <dave(a)musical-dot-demon-dot-co.uk> ha scritto nel messaggio
news:uvxUuSRlKHA.2184(a)TK2MSFTNGP04.phx.gbl...

> I am getting increasingly frustrated at the shortcomings of CStdioFile for
> reading Unicode text files (unless I've missed something).
> I've found a nice looking class on CodeProject
> <http://www.codeproject.com/KB/files/textfiledocument.aspx> but it is
> several years old.
>
> Has something been introduced into MFC to do this sort of thing in the
> last couple of Visual Studio releases? If not, is there something in
> the Win32 API or CRT?

I would suggest CStdioFileEx on CodeProject:

http://www.codeproject.com/KB/files/stdiofileex.aspx

Moreover, since VS2005, there is a Unicode support in CRT for _open and
_wopen, see _O_U16TEXT, _O_U8TEXT and _O_WTEXT flags.

http://msdn.microsoft.com/en-us/library/z0kc8e3z(VS.80).aspx

And, FWIW, some time ago, I shared some code to read and write UTF8 on
CodeGallery as well:

http://code.msdn.microsoft.com/UTF8Helpers

HTH,
Giovanni


From: David Webber on
"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote in message
news:OpENjXRlKHA.5568(a)TK2MSFTNGP02.phx.gbl...
> "David Webber" <dave(a)musical-dot-demon-dot-co.uk> ha scritto nel messaggio
> news:uvxUuSRlKHA.2184(a)TK2MSFTNGP04.phx.gbl...
>
>> I am getting increasingly frustrated at the shortcomings of CStdioFile
>> for reading Unicode text files (unless I've missed something).
>> I've found a nice looking class on CodeProject
>> <http://www.codeproject.com/KB/files/textfiledocument.aspx> but it is
>> several years old.
>>
>> Has something been introduced into MFC to do this sort of thing in the
>> last couple of Visual Studio releases? If not, is there something in
>> the Win32 API or CRT?
>
> I would suggest CStdioFileEx on CodeProject:
>
> http://www.codeproject.com/KB/files/stdiofileex.aspx

Thanks Giovanni, I'll look at that one too.

> Moreover, since VS2005, there is a Unicode support in CRT for _open and
> _wopen, see _O_U16TEXT, _O_U8TEXT and _O_WTEXT flags.

Thanks - I've just discovered it in fopen() and friends too, with an
enhanced 'mode' parameter. The documentation is about as clear as mud when
it comes to binary or text mode, but a bit of experimentation should sort
that out.

> http://msdn.microsoft.com/en-us/library/z0kc8e3z(VS.80).aspx
>
> And, FWIW, some time ago, I shared some code to read and write UTF8 on
> CodeGallery as well:
>
> http://code.msdn.microsoft.com/UTF8Helpers

I'll try to remember that too, but at the moment I only need to read
single-byte text files with the Western European character set, or UTF-16
(in fact more specifically UCS2). (I have a data base of musical instrument
properties in a .txt file which comes in different language versions. So
far single byte stuff with the Western character set has been fine, but I
want to add a Czech version. UCS2 will be fine for this. All I need is
code to read either encoding transparently into wchar_t strings.)

Dave
--
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

From: zeromem on
Also worth a look is EZUTF, which is Non-MFC.

http://www.codeproject.com/KB/files/EZUTF.aspx

On 1/14/2010 4:25 AM, David Webber wrote:
> I am getting increasingly frustrated at the shortcomings of CStdioFile
> for reading Unicode text files (unless I've missed something).
>
> I've found a nice looking class on CodeProject
> <http://www.codeproject.com/KB/files/textfiledocument.aspx> but it is
> several years old.
>
> Has something been introduced into MFC to do this sort of thing in the
> last couple of Visual Studio releases? If not, is there something in the
> Win32 API or CRT?
>
> Dave

From: Tom Serface on
Hi David,

I agree and I also use the CStdioFileEx from
http://www.codeproject.com/KB/files/stdiofileex.aspx although I've redone a
lot of it because I needed UTF-8 as well (it is a really good starting
point). I wish they'd put something like this into MFC's version.

Tom

"David Webber" <dave(a)musical-dot-demon-dot-co.uk> wrote in message
news:uvxUuSRlKHA.2184(a)TK2MSFTNGP04.phx.gbl...
> I am getting increasingly frustrated at the shortcomings of CStdioFile for
> reading Unicode text files (unless I've missed something).
>
> I've found a nice looking class on CodeProject
> <http://www.codeproject.com/KB/files/textfiledocument.aspx> but it is
> several years old.
>
> Has something been introduced into MFC to do this sort of thing in the
> last couple of Visual Studio releases? If not, is there something in
> the Win32 API or CRT?
>
> Dave
> --
> David Webber
> Mozart Music Software
> http://www.mozart.co.uk
> For discussion and support see
> http://www.mozart.co.uk/mozartists/mailinglist.htm