{I+=codeWee;}
[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();
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.