void saveWideFileHead(std::ofstream& out)// 寫入檔案內容前,先寫入BOM { char const* const utf16head = "xFFxFE"; out.write(utf16head, 2); } void saveWideFileContent(std::ofstream& out, wchar_t const* str, int size) { char const* pos = (char const*)str; out.write(pos, size); } void saveWideFileCRLF(std::ofstream& out)// 寫入回車換行符 { char const* const utf16head = "x0Dx00x0Ax00"; out.write(utf16head, 4); } void Test() { std::ofstream of("test.log", std::ios::binary | std::ios::out); saveWideFileHead(of); CString str("hello中國world1234"); saveWideFileContent(of, str, str.GetLength() * 2); saveWideFileCRLF(of); saveWideFileContent(of, str, str.GetLength() * 2); of.close(); }