Before using CString to replace characters, please make sure that encoding is only UTF-16(unicode) format without UTF-8. CString doesn't seems to correctly work with UTF-8.
Actually, you want to write Unicode text, you should specify how many buffer size in bytes when performing CFile::Write.
Note:If the file starts with a Unicode byte-order mark [0xFF 0xFE] or [0xFE 0xFF], the document is considered to be in UTF-16 encoding. Otherwise it is in UTF-8.