其他分享
首页 > 其他分享> > MFC中写入汉语到文本文档

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.输出的文本

标签:文本文档,old,WriteString,setlocale,写入,CTYPE,Writefile,MFC,设置
来源: https://www.cnblogs.com/gaozihan/p/10969013.html