解决办法如下:
(1)、将写入字符串转换编码为:ANSI
char* pBuffer = NULL; long lBufferSize; lBufferSize = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, m_sRtf, -1, NULL, 0, NULL, NULL); pBuffer = new char[lBufferSize + 1]; WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, m_sRtf, -1, pBuffer, lBufferSize + 1, NULL, NULL); CFile file(_T("E://a.rtf"), CFile::modeCreate | CFile::modeWrite); file.Write(pBuffer, lBufferSize); file.Close();
</pre><pre name="code" class="cpp"><span style="font-size:24px;">(2)、写入之前调用如下函数:</span>
<span style="font-size:24px;"> </span>
</pre><pre name="code" class="cpp"><span style="white-space:pre"> </span>char* old_locale = _strdup( setlocale(LC_CTYPE,NULL) ); setlocale( LC_CTYPE, "chs" );
</pre><pre name="code" class="cpp"> <span style="font-size:24px;">(3)、写入结束后调用如下函数:</span>
<span style="white-space:pre"> </span>setlocale( LC_CTYPE, old_locale ); free( old_locale );//还原区域设定
时间: 2024-10-03 13:46:58