我是靠谱客的博主 文艺百褶裙,这篇文章主要介绍解决CFile 写入中文后换行,现在分享给大家,希望可以做个参考。

CFile 正常写入中文

CFile myFile;
BOOL isopen=myFile.Open(filename, CFile::modeReadWrite|CFile::modeCreate | CFile::typeBinary|CFile::shareDenyNone);
if(!isopen)
AfxMessageBox("不能打开文件!");
CFile myFile();
CString EditContent;
m_EditText->GetWindowText(EditContent);
LPCTSTR str = EditContent.GetBuffer( EditContent.GetLength());
myFile.Write(str,EditContent.GetLength()*sizeof(CHAR));
myFile.Close();


例子:

#include <afx.h>
#include <iostream.h>
int main(){
CString str1="中国rn";
LPCTSTR s1=str1.GetBuffer(str1.GetLength());
CString str2="人民rn";
LPCTSTR s2=str2.GetBuffer(str2.GetLength());
CString str3="五湖四海rn";
LPCTSTR s3=str3.GetBuffer(str3.GetLength());
TRY
{
CFile file("hello.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
file.Write(s1,str1.GetLength()*sizeof(CHAR));
file.Write(s2,str2.GetLength()*sizeof(CHAR));
file.Write(s3,str3.GetLength()*sizeof(CHAR));
file.Close();
}
CATCH (CFileException, e)
{
switch (e->m_cause)
{
case CFileException::accessDenied:
TRACE("File Access Deniedn");
break;
case CFileException::badPath:
TRACE("Invalid Pathn");
break;
case CFileException::diskFull:
TRACE("Disk Fulln");
break;
case CFileException::fileNotFound:
TRACE("File Not Foundn");
break;
case CFileException::hardIO:
TRACE("Hardware Errorn");
break;
case CFileException::lockViolation:
TRACE("Attemp to lock region already locked n");
break;
case CFileException::sharingViolation:
TRACE("Sharing Violation -load share.exen");
break;
case CFileException::tooManyOpenFiles:
TRACE("Too Many Open Filesn");
break;
}
}
str1.ReleaseBuffer();
str2.ReleaseBuffer();
str3.ReleaseBuffer();
END_CATCH
return 0;
}










最后

以上就是文艺百褶裙最近收集整理的关于解决CFile 写入中文后换行的全部内容,更多相关解决CFile内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部