MFC中写入汉语到文本文档

目录

1.首先要引入头文件

#include <locale>

2.在打开文件后,要进行设置,然后在关闭文档时,进行设置的后处理

CStdioFile Writefile;
if (!Writefile.Open(WorkPath+_T("\\")+filename + _T(".dat"),CFile::modeWrite|CFile::modeCreate))
{
    AfxMessageBox(_T("创建APDL文件失败"));
    return;
}   

    char* old_locale = strdup(setlocale(LC_CTYPE,NULL));//设置local
    setlocale(LC_CTYPE,"chs");//设置汉语显示

    Writefile.WriteString(_T("!程序头 \n"));
    Writefile.WriteString(_T("FINISH \n"));
    Writefile.WriteString(_T("/CLEAR \n"));
    CString temp;
    temp.Format(_T("/FILENAME, %s \n"),filename);//名字
    Writefile.WriteString(temp);
    Writefile.WriteString(_T("/FILENAME, Harmonic \n"));
    Writefile.WriteString(_T("/PREP7 \n\n"));
    Writefile.Flush();
    Writefile.Close();

    setlocale(LC_CTYPE,old_locale);//释放内存
    free(old_locale);

3.输出的文本

MFC中写入汉语到文本文档

上一篇:AT2060 【Minimum Sum】


下一篇:1.11内存四区(栈区)