I am trying to use members of the MFC CStdioFile class to read the contents
of a UNICODE file (created by NOTEPAD).
I can read if if I use _wfopen_s to open the file and fgetws to read the
file.
However, when I open the file with CStdioFile::Open(), and read with
CStdio::ReadString() and examine the contents of the buffer using the
debugger's memory window, I see that each character read from the file is
stored in 16 bits (as I expect), but there is a 16-bit zero between all of
the characters.
Here is a snippet of my code:
CStdioFile f;
CString fileline = _T("");
f.Open(fn, CFile::modeRead);
while (f.ReadString(fileline) && bNotDone) {
.
.
In the debugger, I can see that fileline is using wchar_t for its buffer.
I have set the project Character Set property to "Use Unicode Character Set".
I've searched through the documentation, but haven't be able to find any
solution to this other than to not use CStdioFile.
Thanks in advance for your help.
Jim
Cheers
Check Abdoul
---------------------
"Jim Walsh" <JimW...@discussions.microsoft.com> wrote in message
news:3056A6C8-007F-4EAB...@microsoft.com...
Tom
"Jim Walsh" <JimW...@discussions.microsoft.com> wrote in message
news:3056A6C8-007F-4EAB...@microsoft.com...
>I think the CStdioFile class will work with Unicode files if you compile
>your program as Unicode so it uses the Unicode version of MFC. If you
>compile as ANSI it only reads ANSI files.
The documentation isn't really explicit on this but I tried this a while
back, and IIRC, CStdioFile *always* assumes one is reading the old fashioned
1 byte per character text files. If you compile with UNICODE it just
reads them into wide strings; it doesn't read Unicode text files.
But the ReadString() method is virtual as Check Abdoul says, so one can
override it.
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm
Regards,
Victor
"Jim Walsh" <JimW...@discussions.microsoft.com> wrote in message
news:3056A6C8-007F-4EAB...@microsoft.com...
Very frustrating to blow away a day trying to get this to work.
My work around using _wfopen_s and fgetws works fine.
Do you think that there is any advantage to me in pursuing an override of
CStdioFile::ReadString()?
Jim
Send me an email and I'll send you a class where this is already done. It's
too much to post here.
Tom
"Jim Walsh" <JimW...@discussions.microsoft.com> wrote in message
news:E16F025F-8C25-463A...@microsoft.com...
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm