重载
//AB类,重载<<, >>提供输入,并把输入内容放到文件里面,并输出到屏幕上(main里面可以写除函数外的代码)#include"iostream.h"
#include"fstream.h"
#include"stdio.h"
class AB
{ public:
AB(){}
friend ifstream& operator >>(ifstream& in,AB& a);
friend ofstream& operator <<(ofstream& in,AB& a);
private:
char ch[100];
};
main()
{ ifstream in;
ofstream out;
AB a(in);
out.open("abc.txt");
if(!out.fail())
{ cout<<"error!"<<endl;
exit(1);
}
in>>a;
out<<a<<endl;
out.close();
}
ifstream& operator >>(ifstream& in,AB& a)
{ in>>a.ch;
return in;
}
ofstream& operator <<(ofstream& out,AB& a)
{ out<<a.ch;
return out;
}