使用的平台:vs2013 控制台

from: http://bbs.csdn.net/topics/360229403

xiayuanzhong:

ofstream ofs( "test.txt", ios::binary | ios::out );
ifstream ifs( "Test_Read.txt", ios::binary | ios::in );
wchar_t temp[ 2 ];
ifs.read( (char *)temp, 2 );
memset( temp, L'\0', sizeof(temp) );
ofs.write( "\xFF\xFE", 2 );
int k = 0;
while ( 1 ) {
k ++;
ifs.read( (char *)temp, 2 );
if ( ifs.eof( ) ) break;//经验表明,放在这里最恰当!~
ofs.write( (char *)temp, 2 );
}
ifs.close( );
ofs.close( );

  

unicode的TXT使用经验:

1.输出 换行符

  ofstream ofs_c(FILE_NAME_C, ios::binary | ios::out);

  ofs_c.write("\x0D\x00\x0A\x00", 4);// "\r\n"

2.输出空格

  WCHAR_NULL8(ofs) (ofs).write("\x20\x00\x20\x00\x20\x00\x20\x00", 8);//" " x 4

用ofstream/ifstream 读写Unicod的TXT的更多相关文章

  1. C++读写文件ofstream,ifstream,fstream)[转]

    在看C++编程思想中,每个练习基本都是使用ofstream,ifstream,fstream,以前粗略知道其用法和含义,在看了几位大牛的博文后,进行整理和总结: 这里主要是讨论fstream的内容:[ ...

  2. C++文件读写详解(ofstream,ifstream,fstream)

    C++文件读写详解(ofstream,ifstream,fstream) 这里主要是讨论fstream的内容: #include <fstream> ofstream //文件写操作 内存 ...

  3. 【转载】C++文件读写详解(ofstream,ifstream,fstream)

    原文:http://blog.csdn.net/kingstar158/article/details/6859379 在看C++编程思想中,每个练习基本都是使用ofstream,ifstream,f ...

  4. 【转】C++文件读写详解(ofstream,ifstream,fstream)

    转:http://blog.csdn.net/kingstar158/article/details/6859379 摘要:具体用法,上面链接中,文章写的很详细,讲解ofstream,ifstream ...

  5. c++ ofstream & ifstream文件流操作

    ofstream是从内存到硬盘,ifstream是从硬盘到内存,其实所谓的流缓冲就是内存空间; //ofstream & ifstream inherit from istream class ...

  6. C#读写记事本(txt)文件

    C#写入记事本(txt)文件方法一: FileStream stream = new FileStream(@"d:\aa.txt",FileMode.Create);//file ...

  7. python读写不同编码txt文件

        以后整理规范 import os import codecs filenames=os.listdir(os.getcwd()) out=file("name.txt",& ...

  8. clutter recoder

    cin >> ch; cin.get(ch);区别读取输入是否忽略空格.制表等; char ch; ; cout << "Enter characters;enter ...

  9. 文件操作ofstream,open,close,ifstream,fin,依照行来读取数据, fstream,iosin iosout,fio.seekg(),文件写入和文件读写,文件拷贝和文件

     1.ofstream,open,close 写入文件 #include<iostream> #include<fstream> using namespace std; ...

随机推荐

  1. PAT 天梯赛 L1-004. 计算摄氏温度 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-004 AC代码 #include <iostream> #include <cstdio&g ...

  2. js获取iframe和父级之间元素,方法、属,获取iframe的高度自适应iframe高度

    摘自:http://blog.csdn.net/kongjiea/article/details/38870399 1.在父页面 获取iframe子页面的元素 (在同域的情况下 且在http://下测 ...

  3. CSS流体(自适应)布局下宽度分离原则

    CSS流体(自适应)布局下宽度分离原则 这篇文章发布于 2011年02月28日,星期一,00:48,归类于 css相关. 阅读 73990 次, 今日 5 次 by zhangxinxu from h ...

  4. openstack认证实践

    环境: 客户端:负责发送请求, 服务器:负责接受请求: 认证服务器keystone:负责认证 具体认证步骤: 1.客户端首先进行签名计算,将得到的签名字符串作为authorization发给keyst ...

  5. [洛谷3041]视频游戏的连击Video Game Combos

    题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...

  6. 监控系统信息模块psutil

    About psutil (python system and process utilities) is a cross-platform library for retrieving inform ...

  7. JSP导入包

    1. <%@page import="java.util.Date, mianBao.*, z_utils.*"%> 2. 3.

  8. C语言中链接影响程序的细节

    参考:<深入理解计算机系统>  7.61节  链接器如何解析多重定义的全局符号 基本的原则是这样的:对于所有的全局符号,函数和已初始化的全局变量是强符号,未初始化的全局变量是弱符号. Un ...

  9. 报错HTTP Status 500 - Unable to instantiate Action

    报错如下: HTTP Status 500 - Unable to instantiate Action, visitAction, defined for 'visit_toAddPage' in ...

  10. bitmap==null

    bitmap==null 一.问题介绍 调试找bug的过程出现bitmap==null,而传过来创建bitmap的byte array有数据, 结果看了函数说明: 果断知道是那个图片没有办法decod ...