解决CFile 写入中文后换行
来源:互联网 发布:c语言经典编程题pdf 编辑:程序博客网 时间:2024/04/28 06:38
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="中国\r\n";LPCTSTR s1=str1.GetBuffer(str1.GetLength());CString str2="人民\r\n";LPCTSTR s2=str2.GetBuffer(str2.GetLength());CString str3="五湖四海\r\n";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 Denied\n");break;case CFileException::badPath:TRACE("Invalid Path\n");break;case CFileException::diskFull:TRACE("Disk Full\n");break;case CFileException::fileNotFound:TRACE("File Not Found\n");break;case CFileException::hardIO:TRACE("Hardware Error\n");break;case CFileException::lockViolation:TRACE("Attemp to lock region already locked \n");break;case CFileException::sharingViolation:TRACE("Sharing Violation -load share.exe\n");break;case CFileException::tooManyOpenFiles:TRACE("Too Many Open Files\n");break;}}str1.ReleaseBuffer();str2.ReleaseBuffer();str3.ReleaseBuffer();END_CATCHreturn 0;}
0 0
- 解决CFile 写入中文后换行
- CFile写入中文,正常显示并换行
- CFile写入换行的方法
- 解决CFile 中换行问题
- java 中的写入后换行
- CFile 读写文件 (解决汉字,换行,空字符问题) .
- CFile写入文件
- 解决js 写入中文乱码
- 解决UNICODE字符集下CStdioFile的Writestring无法写入中文的问题和在在原文件后写入文件
- MFC/C++ CFile写入文件数据,输出utf-8的文本。(防止中文乱码)
- CFile创建文件,写入,写入完毕
- 解决Atom中文无法自动换行问题
- 解决shell脚本中 echo 怎么写入换行到文件
- ssh2 中文写入数据库出错的解决
- 解决hibernate写入mysql中文乱码问题
- CStdioFile WriteString 无法写入中文 已解决
- python中文写入CSV乱码解决
- 使用Unicode字符集时用CFile把中文写入txt文件再用记事本打开出现乱码的问题
- HDU 2088 Sky数
- Java--常用jar包用途
- 进制转换
- scala中的var,val,immutable,mutable理解小结
- Spark入门学习
- 解决CFile 写入中文后换行
- 内部排序-堆排序
- LeetCode 213:House Robber II
- 提问的智慧
- Java NIO使用及原理分析 (一)
- Linux 递归经典:fork 炸弹
- 多线程的创建
- 黑马程序员--C语言自学笔记---04分支结构
- 数组和指针