
MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. UOpenFlag |= CFile::typeBinary // Unicode need add CFile::typeBinaryīOO元2 bRet = logFile.Open(pszFilePath, uOpenFlag, &ex) įlog.Write((void*)&unicodeFlag, sizeof(WORD)) UINT uOpenFlag = CFile::shareDenyNone | CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate If (pszLog = NULL || pszFilePath = NULL)īOOL bFileExsit = PathFileExists(pszFilePath) void WriteLog(LPCTSTR pszLog, LPCTSTR pszFilePath) I have found a sample about using CStdioFile. At the very least, this is a jarring inconsistency, as CString can contain UNICODE, and ofstream canĪccept CString input, for example: CString Test = _T("abc") The fact that FILE supports UNICODE, UTF-8 & UTF-16, while ofstream does not is a clear indication that VS does not, yet, fully support UNICODE. In addition to this modification, I had to ensure that the file was explicitly closed, as ofstream files are closed automatically when the deconstructor is called, but FILE files are not! I also was able to remove the code to write BOM to the file,Īs this is automatic with FILE when css=UNICODE or UTF-8 or UTF-16. The basic idea is to open the file with: FILE *fStream Įrrno_t e = _tfopen_s(&fStream, TargetFile, _T("wt,ccs=UTF-8")) ĪfxMessageBox(_T("Export file cannot be opened"), MB_ICONINFORMATION) ĬStdioFile File(fStream) // open the file from this stream Full disclosure, a coworker pointed me to this solution, which he obtained from StackOverflow: As it turns out, the answer is fairly simple, as I expected it should be.
