ioSteam ±à³Ì

Àý×Ó

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
//#include <streambuf>
using namespace std;
class MyBuf : public streambuf
{
   public:
      MyBuf(){
      }
      virtual ~MyBuf(){
      }
      virtual int overflow (int c) {
         printf("%c",c);
      }
};
int i=0;
ostream & xx (ostream & in)
{
   printf("i is %d.\n",i++);
   return in;
}
ios&  xx2 (ios & in,int para)
{
   printf("i is %d. param is %d\n",i++,para);
}
smanip<int>
fillblank(int no)
{
   return (smanip<int>(&xx2, no));
}


struct point{
      int x ;
      int y;
};
ostream & operator << (ostream & in ,struct point & p)
{
   in << "x = " << p.x << ";"
      << "y = " << p.y << ";";
   return cout ;
}
int main (int argc, char * argv[])
{
   MyBuf a;
   ostream o(&a);
   o << "hello " << endl;
   cout << xx << "abc" << xx << "def" << endl;
   ofstream t("/tmp/b.txt");
   struct point apoint;
   apoint.x = 1;
   apoint.y = 1200;
   t<< apoint << "\nhello world" << endl;
   cout << fillblank(100) << "hello" << fillblank (2000) << endl;

   return 0;
}