基于windows API 的 用CString 保存Unicode 文本的代码示例
来源:互联网 发布:拓扑排序算法流程图 编辑:程序博客网 时间:2024/06/05 04:06
要完成课程作业 遗传算法示例,需要把一些信息保存到文本当中。 左右折腾几个小时,最后完美解决一些问题。
比如: 1. 用UlteraEdit 打开时,总提示是否讲文本转换到dos 格式。
2. cstring 保存会被截掉一般。
FILE * myfile;myfile = CreateFile(_T("D:\\SGAdata.txt"),GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);if(myfile == INVALID_HANDLE_VALUE)TRACE("open File error !");DWORD bytesWriten = 0;WCHAR UnicodeHeadFlag = 0xfeff; // 这个是表示本文是Unicode 文本,必须要写。 //由于大段\小段存储的原因,本来的标准Unicode 头 FF FE 要写成 FE FFif (WriteFile(myfile,&UnicodeHeadFlag,sizeof(WCHAR),&bytesWriten,NULL)){TRACE("write file success. %d byte is written .\n",bytesWriten);}FlushFileBuffers(myfile);CString str(_T("******************************************\r\n")); // 这是要保存的 CString // 在后面的 \r\n 能完美解决 提到的问题一 。if (WriteFile(myfile,str,str.GetLength()*2,&bytesWriten,NULL)){ // 这里的 str.GetLength()*2 也需要注意,这个能解决问题二。TRACE("write file success. %d byte is written .\n",bytesWriten);}FlushFileBuffers(myfile);str = _T(" This File Is The Output Data for SGA \r\n");if (WriteFile(myfile,str,str.GetLength()*2,&bytesWriten,NULL)){TRACE("write file success. %d byte is written .\n",bytesWriten);}FlushFileBuffers(myfile);str = (_T("******************************************\r\n"));if (WriteFile(myfile,str,str.GetLength()*2,&bytesWriten,NULL)){TRACE("write file success. %d byte is written .\n",bytesWriten);}FlushFileBuffers(myfile);对了,最后还要用closehandle 关闭文件。
- 基于windows API 的 用CString 保存Unicode 文本的代码示例
- 基于PHP的车辆违章查询api调用代码示例
- unicode的CString转
- CString 在Unicode代码下转char的方法
- hbase的api代码示例
- Ansi Unicode UTF8之间的转换与写入文本示例。
- CString到UNICODE的转换
- unicode方式保存文本
- 簡單的Windows API示例
- 过滤 外文unicode文本中字符的代码
- Mininet的示例代码教会你用python API
- [代码]基于RNN的文本生成算法
- 基于Windows Azure 包、Service Provider Foundation 和 Virtual Machine Manager的示例门户代码
- VB6基于Windows API的Modbus RTU/ASCII/TCP的主站实现代码
- Unicode类型的CString转化为char*
- char*字符串转unicode下的CString
- UniCode 下 CString 转 char* 的方法
- STL string与CString的Unicode字符集
- 如何知道远程电脑某一端口是否打开?
- Android 自动化测试
- MEF学习
- get/post时中文乱码问题的解决办法
- 走出“搜索引擎营销”三个误区
- 基于windows API 的 用CString 保存Unicode 文本的代码示例
- 开发商:Facebook硬核游戏更具盈利性—Flash的专注符合开发商需求
- 企业需要什么样的ERP运维服务
- python 自己写的十进制转所有进制
- 第十三周第三天
- [置顶]用汇编的眼光看C++(之 总结篇)
- LBP算子介绍
- java uuid 生成方法
- 关于pthread_testcancel()的疑问