Latest version have UTF-8 support! Internally it is still stored as unicode.
Notes for using Unicode file class
The buffer length required by some functions is in terms of wide-characters, not bytes
Example, for writing string of L"Hello", you specify 5, not 10.
If you specify zero as the buffer length for write functions, it will treat the string to be
written as null terminated.
For Read() function, you must specify the buffer length, except for ReadLine()
You must pass a null pointer to Read() and ReadLine().
You must delete the array returned by Read() and ReadLine() yourself.
Please use binary mode, when opening unicode file.
Please use text mode, when opening UTF-8 file.
// open for writing
bool bRet = uf.Open( _T("D:\\test.txt"), _T("wb") );
// open for appending
//bool bRet = uf.Open( _T("D:\\test.txt"), _T("ab") );
if( bRet )
uf.WriteLine( _T("Thank god is friday!") );
Call IsUnicodeFile() immediately after opening to determine it is a unicode file
Before using ReadLine(), you must call ReadAll() once;
bool bRet = uf.Open( "D:\\uc.txt", "rb" );
if( bRet )
wchar_t *pwchar = 0;
int nBufLen = 0;
while( uf.ReadLine( pwchar, nBufLen ) )
if( pwchar )
// Do your stuff here
delete  pwchar;
pwchar = 0;
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)
The Next Version of Android - Some of What's Coming