Reading Unicode from a text file
-
I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,
-
I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,
Every (or at least most) text-file read operations have their widechar (unicode) versions, like for fgets there is fgetws. Did you try using those?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,
You just need to specify the number of bytes to read in the
ReadFile
API. Unicode and non-unicode is decided based upon how it is interpreted. So you're probably not giving the correct number of bytes to read. Try doubling it.«_Superman_» I love work. It gives me something to do between weekends.
-
I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,
You mentioned MFC so I suggest you use
CStdioFile
to read text files. You have to set the flagCFile::typeBinary
in order to read Unicode strings and of course your app has to be Unicode enabled. -
You mentioned MFC so I suggest you use
CStdioFile
to read text files. You have to set the flagCFile::typeBinary
in order to read Unicode strings and of course your app has to be Unicode enabled. -
When you say that the app has to be Unicode enabled, do you mean building it as Unicode as opposed to release?
You have to define
_UNICODE
andUNICODE
and you have to set the Entry-Point symbol in the Linker output options towWinMainCRTStartup
That's for both configurations, Release and Debug. -
I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,
See this A UTF-16 Class for Reading and Writing Unicode Files[^]
-Sarath. "Great hopes make everything great possible" - Benjamin Franklin
My blog - Sharing My Thoughts
-
You have to define
_UNICODE
andUNICODE
and you have to set the Entry-Point symbol in the Linker output options towWinMainCRTStartup
That's for both configurations, Release and Debug.Oh i see... So if i just do this: "You have to define _UNICODE and UNICODE and you have to set the Entry-Point symbol in the Linker output options to wWinMainCRTStartup" Is that equivalent to building as unicode or does that serve a totally different purpose relating to the output of the application?
-
When you say that the app has to be Unicode enabled, do you mean building it as Unicode as opposed to release?
LCI wrote:
do you mean building it as Unicode as opposed to release?
Unicode is not 'opposed' to Release. You can build unicode enabled applications both in debug and release modes.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Oh i see... So if i just do this: "You have to define _UNICODE and UNICODE and you have to set the Entry-Point symbol in the Linker output options to wWinMainCRTStartup" Is that equivalent to building as unicode or does that serve a totally different purpose relating to the output of the application?
LCI wrote:
Is that equivalent to building as unicode
Yes. The output of your app depends entirely on the functions/classes you use for writing to files.