使用的平台: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. iOS 自定义滑动切换TabbarItem 觉得设计丑也要做出来的UI效果。。。

    UI丑却要继续做的感言: 对UI不满意的时候,就会觉得丑爆了,时间长了,却丑习惯了. 论前一阵子Tabbar 多丑,丑得最后不要tabbar了...但是自定义tabbar 和遇到的问题解决的过程可以记 ...

  2. Spring 配置log4j和简单介绍Log4J的使用

    Log4j 是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事 件记录器.UNIX Syslog守护进程等 ...

  3. 跟着实例学习ZooKeeper的用法: 分布式锁

    锁 分布式的锁全局同步, 这意味着任何一个时间点不会有两个客户端都拥有相同的锁. 可重入锁Shared Reentrant Lock 首先我们先看一个全局可重入的锁. Shared意味着锁是全局可见的 ...

  4. flex NaN

    如果该值为NaN(非数字),则返回true:否则返回false.public function isNaN(num:Number):Boolean 举例:NaN值不是int或uint数据类型的成员.f ...

  5. 通过自动回复机器人学Mybatis:搭建核心架构

    imooc视频学习笔记 ----> URL:http://www.imooc.com/learn/154 MessageDao.java package com.imooc.dao; impor ...

  6. Kali Linux学习笔记

    1. 重装grub 重装windows后MBR被覆盖导致linux无法启动,通过U盘进入live后执行以下命令: mount /dev/sda5 /mnt //此处是将linux系统根目录挂载到mnt ...

  7. Aggregate Services

    https://stackoverflow.com/questions/7199097/constructor-injection-into-a-base-class-using-autofac Ca ...

  8. 【P3254】圆桌问题(最大流,洛谷)

    看到题目,产生第一反应,是否可以匹配的是这么多.那么连边跑一遍最大流就行了. 从源点向每个单位连一条长度为l的边,然后所有单位和餐桌分别连边,流量为1,所有餐桌向汇点连边,流量为餐桌容量.然后跑一遍最 ...

  9. Python流程控制与函数

    if >>> x = int(raw_input("Please enter an integer:")) Please enter an integer:42 ...

  10. 配置mybatis-config.xml出现过很诡异的现象

    1 首先得保证包的导入正确 2 然后如果把mybatis-config.xml放在src的某个文件夹下,最后能够build path 3 之后一直报 Archive for required libr ...