Click here to Skip to main content
13,409,878 members (38,263 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 8 Jul 2004

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

, 8 Jul 2004
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.


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

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.


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.


  • 9-Jul-2004

    Initial version.


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


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_ape30-Aug-04 0:10
memberd00_ape30-Aug-04 0:10 
GeneralRe: Compiler Error Pin
Uwe Sedlack11-Mar-05 7:12
sussUwe Sedlack11-Mar-05 7:12 
GeneralCStdioFileEx Pin
David Pritchard14-Jul-04 12:51
memberDavid Pritchard14-Jul-04 12:51 
Generalhalf-baked conversion Pin
umeca7413-Jul-04 20:51
memberumeca7413-Jul-04 20:51 
GeneralRe: half-baked conversion Pin
Sven Axelsson16-Jul-04 1:42
memberSven Axelsson16-Jul-04 1:42 
GeneralRe: half-baked conversion Pin
umeca7419-Jul-04 4:01
memberumeca7419-Jul-04 4:01 

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

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

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