Using a CFile object, the code opens a file with "ANSI as UTF8" encoding. Once the text is modified and the file is overwritten using the write function, the encode changes to ANSI.
Tried the following code to change the encoding of the text being written.
CComBSTR bstrContent;
m_spDOMDocument->get_xml(&bstrContent);
CString strContent(bstrContent);
CT2CA outputString(strContent, CP_UTF8);
File.SetLength(0);
File.SeekToBegin();
File.Write(strContent, ::strlen(outputString));
File.SeekToBegin();
This is as suggested in UTF-8, CString and CFile? (C++, MFC)
The file still gets written with ANSI encoding. How can the file be written in UTF 8 format?