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

xiaoxiao2021-02-28  103

// 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;}

转载请注明原文地址: https://www.6miu.com/read-74101.html

最新回复(0)