Click here to Skip to main content
11,570,945 members (57,949 online)
Click here to Skip to main content

Simple class to read and write from an UTF-8 encoded file

, 8 Jul 2004 55.4K 1.5K 14
Rate this:
Please Sign up or sign in to vote.
A class derived from CStdioFile to read and write from an UTF-8 encoded file.

Disclaimer

This will certainly look like a very thin article, but it's all in the source Sniff | :^)

I have looked around quite a bit, both here at Code Project and elsewhere, since I thought that there must be someone who has posted such a class already. Well, I couldn't find any, so here is my own quick hack to solve the problem.

Background

The CStdioFile_UTF8 class was initially done as a step towards making Dan Goodson's excellent TodoList program support Unicode. I'm posting it here in case someone else finds it useful.

Using the code

Use the class as a plug in replacement for MFC CStdioFile. The class overrides the ReadString and WriteString functions in order to do some conversion. It also provides the functions ReadBOM and WriteBOM to handle an optional bute order mark in the file.

If _UNICODE is defined, the UTF16 strings used internally are converted from/to UTF8 as used in the file. If the symbol is not defined, the class acts exactly like the parent class CStdioFile.

History

  • 9-Jul-2004

    Initial version.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sven Axelsson
Web Developer
Sweden Sweden
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralCompiler Error Pin
d00_ape29-Aug-04 23:10
memberd00_ape29-Aug-04 23:10 
I can't compile the CStdioFile_UTF8 class

I got the following error when compiling the CStdioFile_UTF8 class:

----
error C2065: 'lpszFileName' : undeclared identifier
----

on this line in the CStdioFile_UTF8.h file

class CStdioFile_UTF8 : public CStdioFile
{
....
CStdioFile(LPCTSTR lpszFileName, UINT nOpenFlags) : CStdioFile(lpszFileName, nOpenFlags) {}

...
}

whats wrong???

_____________________________

...and justice for all

APe
GeneralRe: Compiler Error Pin
Uwe Sedlack11-Mar-05 6:12
sussUwe Sedlack11-Mar-05 6:12 
GeneralCStdioFileEx Pin
David Pritchard14-Jul-04 11:51
memberDavid Pritchard14-Jul-04 11:51 
Generalhalf-baked conversion Pin
umeca7413-Jul-04 19:51
memberumeca7413-Jul-04 19:51 
GeneralRe: half-baked conversion Pin
Sven Axelsson16-Jul-04 0:42
memberSven Axelsson16-Jul-04 0:42 
GeneralRe: half-baked conversion Pin
umeca7419-Jul-04 3:01
memberumeca7419-Jul-04 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 9 Jul 2004
Article Copyright 2004 by Sven Axelsson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid