[C++] MFC: How to Read and Write Text Files in Unicode through CStdioFile
//
// For Writing ----------------------------------
//
// Open the file with the specified encoding
FILE *fStream;
errno_t e = _tfopen_s(&fStream, _T("\test.txt"), _T("wt,ccs=UNICODE")); // or ccs=UTF-8
if (e != 0) return; // failed..
CStdioFile f(fStream); // open the file from this stream
f.WriteString(_T("Test"));
f.Close();
//
// For Reading -----------------------------------
//
// Open the file with the specified encoding
FILE *fStream;
errno_t e = _tfopen_s(&fStream, _T("\test.txt"), _T("rt,ccs=UNICODE")); // or ccs=UTF-8
if (e != 0) return; // failed..CString sRead;
CStdioFile f(fStream); // open the file from this stream
CString sRead;
f.ReadString(sRead);
f.Close();