c++疯狂代码之读和写。。。(用读操作来触发写)

来源:互联网 发布:spark php客户端 编辑:程序博客网 时间:2024/06/05 07:22

// dffffffff.cpp : Defines the entry point for the console application.
//
#include <StdAfx.h>
#include   <iostream>
#include   <locale>
#include   <fstream>
#include <string>
#include <sstream>
using namespace std;
//创建全局对象。这些对象保存在全局区。

ofstream *pof=new ofstream("adfa",ios::app|ios::out);
ostream *pOut=new ostream(pof->rdbuf()); 
ifstream* pif=new  ifstream("adfa",ios::ate|ios::in);
istream *pIn=new istream(pif->rdbuf());

void MyWrite(string s){
 (*pOut)<<s<<endl;
 //pof->close();
}
bool MyRead(string &sr,ostream *pOut){
    /*********************输出,从文件读数据********************************************/
    //创建输入缓冲

 //绑定(输入)
 pIn->tie(pOut);
 return (*pIn)>>sr;
 //pIn->clear();
 //ifs.close();
}

int main(int argc, char* argv[])

    MyWrite("12345");
 MyWrite("23333333312");
 MyWrite("sdafa");
 string ms;
    while(MyRead(ms,pOut)){
  cout<<ms;
 }
 return 0;
}