IO streambuf introduction

streambuf objects are in charge of providing reading and writing functionality to/from certain types of character sequences, such as external files or strings.

streambuf objects are usually associated with one specific character sequence, from which they read and write data through an internal memory buffer. The buffer is an array in memory which is expected to be synchronized when needed with the physical content of the associated character sequence.

This is an abstract base class, therefore no objects can be directly instantiated from it. The standard hierarchy defines two classes derived from this one that can be used to directly instantiate objects: filebuf and stringbuf.

 

#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
 
 ifstream in ("C://Documents and Settings//gaoqian//Desktop//test.txt");
 int amount = 0;
 if (!in)
 {
  cout<<"input file error"<<endl;
  return -1;
 }
 
 while (!in.get(bs).eof())
 {
  if (in.fail())
   in.clear();
  cout<<char(in.get());
  ++amount;
  cout<<"run times is "<<amount<<"****"<<endl;
 }

 

 //another mean to implement this.
 ifstream in ("C://Documents and Settings//gaoqian//Desktop//test2.txt");
 cout<<in.rdbuf();
 
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值